[OS]miniOS-6

๐Ÿ‘‰๏ธ ๊ทธ๋ž˜ํ”ฝ ๋ชจ๋“œ ์ „ํ™˜๋กœ ์ „ํ™˜ํ•˜๊ณ  ํ™”๋ฉด์— ๋…ธ๋ž€์ƒ‰ ์‚ฌ๊ฐํ˜•์„ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.
Switch to graphics mode and display a yellow rectangle on the screen.

๐Ÿ‘‰๏ธ ์ „์ฒด์ฝ”๋“œ / full code

โœ”๏ธ boot.asm

[org 0x7c00]
bits 16

start:
    ; ๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ ๋ ˆ์ง€์Šคํ„ฐ ์ดˆ๊ธฐํ™”
    ; Initialize data segment registers
    mov ax, 0
    mov ds, ax
    mov es, ax

    ; ----------------------------------------------------
    ; BIOS ์ธํ„ฐ๋ŸฝํŠธ๋ฅผ ์ด์šฉํ•ด 320x200 256์ƒ‰ ๊ทธ๋ž˜ํ”ฝ ๋ชจ๋“œ๋กœ ์ „ํ™˜
    ; Switch to 320x200 256-color graphic mode using BIOS interrupt
    ; ----------------------------------------------------
    mov ah, 0x00        ; ํ™”๋ฉด ๋ชจ๋“œ ์„ค์ • ๊ธฐ๋Šฅ ์„ ํƒ
                        ; Select screen mode set function
    mov al, 0x13        ; 320x200 256์ƒ‰ ๊ทธ๋ž˜ํ”ฝ ๋ชจ๋“œ ๋ฒˆํ˜ธ (Mode 13h)
                        ; 320x200 256-color graphic mode number (Mode 13h)
    int 0x10            ; ๋น„๋””์˜ค ์ธํ„ฐ๋ŸฝํŠธ ํ˜ธ์ถœ -> ํ™”๋ฉด์ด ๊ฒ€์€์ƒ‰ ๊ทธ๋ž˜ํ”ฝ ์ฐฝ์œผ๋กœ ์ „ํ™˜๋จ
                        ; Call video interrupt -> Screen switches to a black graphic window

    ; ๋””์Šคํฌ ์ฝ๊ธฐ (2๋ฒˆ ์„นํ„ฐ๋ถ€ํ„ฐ 1๊ฐœ ์„นํ„ฐ๋ฅผ 0x8000์— ๋กœ๋“œ)
    ; Disk read (Load 1 sector from sector 2 into memory 0x8000)
    mov ah, 0x02
    mov al, 1
    mov ch, 0
    mov cl, 2
    mov dh, 0
    mov bx, 0x8000
    int 0x13

    ; ๋””์Šคํฌ ์ฝ๊ธฐ ์‹คํŒจ ์‹œ ์—๋Ÿฌ ์ฒ˜๋ฆฌ
    ; Error handling if disk read fails
    jc disk_error

    ; ๋กœ๋“œ๋œ 2๋ฒˆ ์„นํ„ฐ ์ฝ”๋“œ๋กœ ์ ํ”„ํ•˜์—ฌ ์‹คํ–‰
    ; Jump to the loaded sector 2 code and execute
    jmp 0x8000

disk_error:
    ; ์—๋Ÿฌ ๋ฐœ์ƒ ์‹œ ์‹œ์Šคํ…œ ๋ฉˆ์ถค (๊ทธ๋ž˜ํ”ฝ ๋ชจ๋“œ์ด๋ฏ€๋กœ ํ…์ŠคํŠธ ์ถœ๋ ฅ์€ ์ผ๋‹จ ์ƒ๋žต)
    ; System hang on error (Text print is omitted for now since it is in graphic mode)
    jmp hang

hang:
    jmp $

; 1๋ฒˆ ์„นํ„ฐ(MBR) ๋นˆ ๊ณต๊ฐ„์„ 0์œผ๋กœ ์ฑ„์šฐ๊ณ  ๋ถ€ํŠธ ์‹œ๊ทธ๋‹ˆ์ฒ˜ ์ถ”๊ฐ€
; Fill remaining space of sector 1 (MBR) with 0 and add boot signature
times 510 - ($ - $$) db 0
dw 0xaa55

โœ”๏ธ sector2.asm

[org 0x8000]
bits 16

start:
    ; ----------------------------------------------------
    ; ๋ฃจํ”„(๋ฐ˜๋ณต๋ฌธ)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ™”๋ฉด์— ํผ์งํ•œ ์‚ฌ๊ฐํ˜• ๊ทธ๋ฆฌ๊ธฐ
    ; Draw a large rectangle on the screen using loops
    ; ----------------------------------------------------
    
    ; ์‚ฌ๊ฐํ˜•์„ ๊ทธ๋ฆฌ๊ธฐ ์œ„ํ•œ ์‹œ์ž‘ ์ขŒํ‘œ ๋ฐ ํฌ๊ธฐ ์„ค์ •
    ; Set starting coordinates and size for drawing the rectangle
    ; ์‹œ์ž‘ ์œ„์น˜(Starting position): X=100, Y=50
    ; ์‚ฌ๊ฐํ˜• ํฌ๊ธฐ(Size): ๊ฐ€๋กœ(Width)=50, ์„ธ๋กœ(Height)=30

    mov dx, 50          ; Y ์ขŒํ‘œ์˜ ์‹œ์ž‘๊ฐ’ ์„ค์ • (์„ธ๋กœ)
                        ; Set the starting value of the Y coordinate (Row)

draw_row_loop:
    mov cx, 100         ; ์ƒˆ ํ–‰(Row)์„ ์‹œ์ž‘ํ•  ๋•Œ๋งˆ๋‹ค X ์ขŒํ‘œ๋ฅผ ๋‹ค์‹œ 100์œผ๋กœ ์ดˆ๊ธฐํ™” (๊ฐ€๋กœ)
                        ; Reset X coordinate to 100 whenever starting a new row (Column)

draw_col_loop:
    ; BIOS ์ธํ„ฐ๋ŸฝํŠธ๋ฅผ ์‚ฌ์šฉํ•ด ํ˜„์žฌ CX, DX ์œ„์น˜์— ์  ์ฐ๊ธฐ
    ; Draw a pixel at the current CX, DX position using BIOS interrupt
    mov ah, 0x0c        ; ํ”ฝ์…€ ์“ฐ๊ธฐ ๊ธฐ๋Šฅ
                        ; Write graphics pixel function
    mov al, 14          ; ์ƒ‰์ƒ ๋ฒˆํ˜ธ (14 = ๋…ธ๋ž€์ƒ‰)
                        ; Color number (14 = Yellow)
    mov bh, 0           ; ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ 0
                        ; Page number 0
    int 0x10            ; ํ”ฝ์…€ ์ถœ๋ ฅ
                        ; Output pixel

    inc cx              ; X ์ขŒํ‘œ๋ฅผ ์˜ค๋ฅธ์ชฝ์œผ๋กœ 1์นธ ์ด๋™
                        ; Move X coordinate 1 pixel to the right
    cmp cx, 150         ; ๊ฐ€๋กœ ๊ธธ์ด๊ฐ€ 50ํ”ฝ์…€์ด ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ (100 + 50)
                        ; Check if the width reached 50 pixels (100 + 50)
    jl draw_col_loop    ; 150๋ณด๋‹ค ์ž‘์œผ๋ฉด ๊ณ„์† ๊ฐ€๋กœ๋กœ ์  ์ฐ๊ธฐ
                        ; If less than 150, keep drawing pixels horizontally

    ; ๊ฐ€๋กœ ํ•œ ์ค„์„ ๋‹ค ์ฑ„์› ์œผ๋ฉด ๋‹ค์Œ ์ค„(์„ธ๋กœ)๋กœ ์ด๋™
    ; Move to the next line (vertically) once a horizontal row is fully drawn
    inc dx              ; Y ์ขŒํ‘œ๋ฅผ ์•„๋ž˜๋กœ 1์นธ ์ด๋™
                        ; Move Y coordinate 1 pixel down
    cmp dx, 80          ; ์„ธ๋กœ ๋†’์ด๊ฐ€ 30ํ”ฝ์…€์ด ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ (50 + 30)
                        ; Check if the height reached 30 pixels (50 + 30)
    jl draw_row_loop    ; 80๋ณด๋‹ค ์ž‘์œผ๋ฉด ๋‹ค์Œ ์ค„๋กœ ๋„˜์–ด๊ฐ€์„œ ๋‹ค์‹œ ๊ฐ€๋กœ ๋ฃจํ”„ ์‹คํ–‰
                        ; If less than 80, go to the next row and run the horizontal loop again

    ; ์‚ฌ๊ฐํ˜• ๊ทธ๋ฆฌ๊ธฐ๊ฐ€ ๋๋‚˜๋ฉด ๋ฌดํ•œ ๋ฃจํ”„๋กœ ๋Œ€๊ธฐ
    ; Infinite loop waiting after rectangle drawing is finished
    jmp $

; 512๋ฐ”์ดํŠธ ํฌ๊ธฐ ๋งž์ถ”๊ธฐ
; Fill up to 512 bytes
times 512 - ($ - $$) db 0

๐Ÿ‘‰๏ธ ์ปดํŒŒ์ผ / compiling

nasm -f bin boot.asm -o boot.bin
nasm -f bin sector2.asm -o sector2.bin
cat boot.bin sector2.bin > temp.bin
dd if=temp.bin of=os.img bs=512 count=2880 conv=sync
qemu-system-x86_64 -drive file=os.img,format=raw,if=floppy -boot a

๐Ÿ‘‰๏ธ ์ฝ”๋“œ์„ค๋ช… / Code Explanation

โœ”๏ธ boot.asm

–๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ ๋ ˆ์ง€์Šคํ„ฐ ์ดˆ๊ธฐํ™”
Initialize data segment registers

start:
    ; ๋ฐ์ดํ„ฐ ์„ธ๊ทธ๋จผํŠธ ๋ ˆ์ง€์Šคํ„ฐ ์ดˆ๊ธฐํ™”
    ; Initialize data segment registers
    mov ax, 0
    mov ds, ax
    mov es, ax

1) ์œ„์˜ ์ฝ”๋“œ๋Š” ์ดˆ๊ธฐํ™”๋งŒ ํ•˜๊ณ  ์ฝ”๋“œ๊ฐ€ ์‚ฌ์šฉ๋˜๋Š” ๋ถ€๋ถ„์ด ์—†์Šต๋‹ˆ๋‹ค.
The code above only performs initialization; there is no part of the code where it is actually used.

2) ํ•˜์ง€๋งŒ ์ด ์ดˆ๊ธฐํ™” ์ฝ”๋“œ๊ฐ€ ์—†์œผ๋ฉด ๋ฐ”๋กœ ์•„๋ž˜์— ์žˆ๋Š” ๋””์Šคํฌ ์ฝ๊ธฐ ๋ช…๋ น์–ด(int 0x13)๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š๊ณ  ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
However, without this initialization code, the disk read command (int 0x13) immediately below it will not work and will result in an error.

3) ์•„๋ž˜ ์ฝ”๋“œ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉ”๋ชจ๋ฆฌ 0x8000์— ์ €์žฅํ•˜๋ผ๊ณ  bx ๋ ˆ์ง€์Šคํ„ฐ๋งŒ ์„ค์ •ํ•ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.
In the code below, I only configured the bx register to store data at memory address 0x8000.

4) ํ•˜์ง€๋งŒ BIOS์˜ ๋””์Šคํฌ ์ฝ๊ธฐ ๊ธฐ๋Šฅ์€ ๋ฌด์กฐ๊ฑด es์™€ bx ๋‘ ๋ ˆ์ง€์Šคํ„ฐ๋ฅผ ํ•ฉ์นœ ์ฃผ์†Œ(es:bx)๋ฅผ ๋ชฉ์ ์ง€๋กœ ์ธ์‹ํ•˜๋„๋ก ํ•˜๋“œ์›จ์–ด ๊ทœ์น™์ด ์ •ํ•ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
However, hardware rules dictate that the BIOS disk read function must treat the address formed by combining the es and bx registers (es:bx) as the destination.

5) ๊ทธ๋ž˜์„œ ์“ฐ๋ ˆ๊ธฐ ๊ฐ’์ด ๋“ค์–ด์žˆ์ง€ ์•Š๊ฒŒ ์ดˆ๊ธฐํ™”๊ฐ€ ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
Therefore, initialization is essential to ensure it does not contain garbage values.

1) ์œ„์˜ ์ฝ”๋“œ๋Š” ์ดˆ๊ธฐํ™”๋งŒ ํ•˜๊ณ  ์ฝ”๋“œ๊ฐ€ ์‚ฌ์šฉ๋˜๋Š” ๋ถ€๋ถ„์ด ์—†์Šต๋‹ˆ๋‹ค.
The code above only performs initialization; there is no part of the code where it is actually used.

2) ํ•˜์ง€๋งŒ ์ด ์ดˆ๊ธฐํ™” ์ฝ”๋“œ๊ฐ€ ์—†์œผ๋ฉด ๋ฐ”๋กœ ์•„๋ž˜์— ์žˆ๋Š” ๋””์Šคํฌ ์ฝ๊ธฐ ๋ช…๋ น์–ด(int 0x13)๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š๊ณ  ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
However, without this initialization code, the disk read command (int 0x13) immediately below it will not work and will result in an error.

3) ์•„๋ž˜ ์ฝ”๋“œ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉ”๋ชจ๋ฆฌ 0x8000์— ์ €์žฅํ•˜๋ผ๊ณ  bx ๋ ˆ์ง€์Šคํ„ฐ๋งŒ ์„ค์ •ํ•ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.
In the code below, I only configured the bx register to store data at memory address 0x8000.

4) ํ•˜์ง€๋งŒ BIOS์˜ ๋””์Šคํฌ ์ฝ๊ธฐ ๊ธฐ๋Šฅ์€ ๋ฌด์กฐ๊ฑด es์™€ bx ๋‘ ๋ ˆ์ง€์Šคํ„ฐ๋ฅผ ํ•ฉ์นœ ์ฃผ์†Œ(es:bx)๋ฅผ ๋ชฉ์ ์ง€๋กœ ์ธ์‹ํ•˜๋„๋ก ํ•˜๋“œ์›จ์–ด ๊ทœ์น™์ด ์ •ํ•ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
However, hardware rules dictate that the BIOS disk read function must treat the address formed by combining the es and bx registers (es:bx) as the destination.

5) ๊ทธ๋ž˜์„œ ์“ฐ๋ ˆ๊ธฐ ๊ฐ’์ด ๋“ค์–ด์žˆ์ง€ ์•Š๊ฒŒ ์ดˆ๊ธฐํ™”๊ฐ€ ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
Therefore, initialization is essential to ensure it does not contain garbage values.

mov bx, 0x8000
int 0x13

— ๊ทธ๋ž˜ํ”ฝ ๋ชจ๋“œ ์ „ํ™˜
Switch Graphics Mode

1) ์ด ๋ถ€๋ถ„์ด ์‹ค์ œ๋กœ ๊ทธ๋ž˜ํ”ฝ ๋ชจ๋“œ๋กœ ์ „ํ™˜ํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.
This is the part where it actually switches to graphics mode.

    mov ah, 0x00        ; ํ™”๋ฉด ๋ชจ๋“œ ์„ค์ • ๊ธฐ๋Šฅ ์„ ํƒ
                        ; Select screen mode set function
    mov al, 0x13        ; 320x200 256์ƒ‰ ๊ทธ๋ž˜ํ”ฝ ๋ชจ๋“œ ๋ฒˆํ˜ธ (Mode 13h)
                        ; 320x200 256-color graphic mode number (Mode 13h)
    int 0x10            ; ๋น„๋””์˜ค ์ธํ„ฐ๋ŸฝํŠธ ํ˜ธ์ถœ -> ํ™”๋ฉด์ด ๊ฒ€์€์ƒ‰ ๊ทธ๋ž˜ํ”ฝ ์ฐฝ์œผ๋กœ ์ „ํ™˜๋จ
                        ; Call video interrupt -> Screen switches to a black graphic window

— ๋‚˜๋จธ์ง€ ์ฝ”๋“œ๋Š” ๊ธฐ์กด ์ฝ”๋“œ์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.
The rest of the code is identical to the existing code.

— ๋ฐ์ดํ„ฐ ์ฝ์–ด์™€ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅํ•˜๊ธฐ,์—๋Ÿฌ์ฒ˜๋ฆฌ,๋ถ€ํŠธ์‹œ๊ทธ๋‹ˆ์ฒ˜ ์ถ”๊ฐ€
Reading data and storing it in memory, error handling, and adding a boot signature.


โœ”๏ธ sector2.asm

๐Ÿ‘ ๋ชจ๋‹ˆํ„ฐ ์ขŒํ‘œ๋Š” ์ขŒ์ธก ์ƒ๋‹จ์ด 0.0์ด๊ณ  ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™ํ•  ์ˆ˜๋ก ์•„๋ž˜๋กœ ์ด๋™ํ•  ์ˆ˜๋ก ๊ฐ’์ด ์ปค์ง‘๋‹ˆ๋‹ค.
For monitor coordinates, the top-left corner is (0, 0), and the values โ€‹โ€‹increase as you move to the right or downward.

— ์œ„์—์„œ ์•„๋ž˜๋กœ 50๋ฒˆ์งธ ํ”ฝ์…€(์ ) ์œ„์น˜์˜ ์ค„์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
It refers to the line located at the 50th pixel (dot) position from the top.

    mov dx, 50          ; Y ์ขŒํ‘œ์˜ ์‹œ์ž‘๊ฐ’ ์„ค์ • (์„ธ๋กœ)
                        ; Set the starting value of the Y coordinate (Row)

— ์™ผ์ชฝ์—์„œ ์˜ค๋ฅธ์ชฝ์œผ๋กœ 100ํ”ฝ์…€ ๋–จ์–ด์ง„ ์œ„์น˜๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
It refers to a position 100 pixels away from the left.

draw_row_loop:
    mov cx, 100         ; ์ƒˆ ํ–‰(Row)์„ ์‹œ์ž‘ํ•  ๋•Œ๋งˆ๋‹ค X ์ขŒํ‘œ๋ฅผ ๋‹ค์‹œ 100์œผ๋กœ ์ดˆ๊ธฐํ™” (๊ฐ€๋กœ)
                        ; Reset X coordinate to 100 whenever starting a new row (Column)

— 1ํ”ฝ์…€์”ฉ ์ ์„ ์ฐ์Šต๋‹ˆ๋‹ค.
Place dots one pixel at a time.

— 50ํ”ฝ์…€์˜ ์ ์„ 1ํ”ฝ์…€์”ฉ ๋‹ค ์ฐ์œผ๋ฉด ๋‹ค์Œ ์ค„๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.
After plotting 50 dots one pixel at a time, it moves to the next line.

draw_col_loop:
    ; BIOS ์ธํ„ฐ๋ŸฝํŠธ๋ฅผ ์‚ฌ์šฉํ•ด ํ˜„์žฌ CX, DX ์œ„์น˜์— ์  ์ฐ๊ธฐ
    ; Draw a pixel at the current CX, DX position using BIOS interrupt
    mov ah, 0x0c        ; ํ”ฝ์…€ ์“ฐ๊ธฐ ๊ธฐ๋Šฅ
                        ; Write graphics pixel function
    mov al, 14          ; ์ƒ‰์ƒ ๋ฒˆํ˜ธ (14 = ๋…ธ๋ž€์ƒ‰)
                        ; Color number (14 = Yellow)
    mov bh, 0           ; ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ 0
                        ; Page number 0
    int 0x10            ; ํ”ฝ์…€ ์ถœ๋ ฅ
                        ; Output pixel

    inc cx              ; X ์ขŒํ‘œ๋ฅผ ์˜ค๋ฅธ์ชฝ์œผ๋กœ 1์นธ ์ด๋™
                        ; Move X coordinate 1 pixel to the right
    cmp cx, 150         ; ๊ฐ€๋กœ ๊ธธ์ด๊ฐ€ 50ํ”ฝ์…€์ด ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ (100 + 50)
                        ; Check if the width reached 50 pixels (100 + 50)
    jl draw_col_loop    ; 150๋ณด๋‹ค ์ž‘์œผ๋ฉด ๊ณ„์† ๊ฐ€๋กœ๋กœ ์  ์ฐ๊ธฐ
                        ; If less than 150, keep drawing pixels horizontally

— dx50์—์„œ 1ํ”ฝ์…€์ด ์ฆ๊ฐ€(inc dx)ํ•˜๋ฉด Y๊ฐ’์ด 51์ด ๋ฉ๋‹ˆ๋‹ค.
If dx50 increases by 1 pixel (inc dx), the Y value becomes 51.

— ์ฆ‰ ๋‹ค์Œ ์ค„๋ถ€ํ„ฐ ์ ์„ ์ฐ์Šต๋‹ˆ๋‹ค.(X:100,Y:51)
In other words, start plotting points from the next line (X:100, Y:51).

— ์„ธ๋กœ ํฌ๊ธฐ๊ฐ€ 30ํ”ฝ์…€์ธ ์‚ฌ๊ฐํ˜•์˜ ์ ์„ ๋‹ค ์ฐ์œผ๋ฉด ๋ฃจํ”„๋ฅผ ๋น ์ ธ๋‚˜๊ฐ‘๋‹ˆ๋‹ค.
The loop exits once all the points of the 30-pixel-high rectangle have been plotted.

— ๊ทธ๋Ÿผ ๊ฐ€๋กœ 50ํ”ฝ์…€ ์„ธ๋กœ 30ํ”ฝ์…€์ธ ๋…ธ๋ž€์ƒ‰ ์‚ฌ๊ฐํ˜•์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Then, you will see a yellow rectangle that is 50 pixels wide and 30 pixels high.

— dx50์—์„œ 1ํ”ฝ์…€์ด ์ฆ๊ฐ€(inc dx)ํ•˜๋ฉด Y๊ฐ’์ด 51์ด ๋ฉ๋‹ˆ๋‹ค.
If dx50 increases by 1 pixel (inc dx), the Y value becomes 51.

— ์ฆ‰ ๋‹ค์Œ ์ค„๋ถ€ํ„ฐ ์ ์„ ์ฐ์Šต๋‹ˆ๋‹ค.(X:100,Y:51)
In other words, start plotting points from the next line (X:100, Y:51).

— ์„ธ๋กœ ํฌ๊ธฐ๊ฐ€ 30ํ”ฝ์…€์ธ ์‚ฌ๊ฐํ˜•์˜ ์ ์„ ๋‹ค ์ฐ์œผ๋ฉด ๋ฃจํ”„๋ฅผ ๋น ์ ธ๋‚˜๊ฐ‘๋‹ˆ๋‹ค.
The loop exits once all the points of the 30-pixel-high rectangle have been plotted.

— ๊ทธ๋Ÿผ ๊ฐ€๋กœ 50ํ”ฝ์…€ ์„ธ๋กœ 30ํ”ฝ์…€์ธ ๋…ธ๋ž€์ƒ‰ ์‚ฌ๊ฐํ˜•์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Then, you will see a yellow rectangle that is 50 pixels wide and 30 pixels high.

    ; ๊ฐ€๋กœ ํ•œ ์ค„์„ ๋‹ค ์ฑ„์› ์œผ๋ฉด ๋‹ค์Œ ์ค„(์„ธ๋กœ)๋กœ ์ด๋™
    ; Move to the next line (vertically) once a horizontal row is fully drawn
    inc dx              ; Y ์ขŒํ‘œ๋ฅผ ์•„๋ž˜๋กœ 1์นธ ์ด๋™
                        ; Move Y coordinate 1 pixel down
    cmp dx, 80          ; ์„ธ๋กœ ๋†’์ด๊ฐ€ 30ํ”ฝ์…€์ด ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ (50 + 30)
                        ; Check if the height reached 30 pixels (50 + 30)
    jl draw_row_loop    ; 80๋ณด๋‹ค ์ž‘์œผ๋ฉด ๋‹ค์Œ ์ค„๋กœ ๋„˜์–ด๊ฐ€์„œ ๋‹ค์‹œ ๊ฐ€๋กœ ๋ฃจํ”„ ์‹คํ–‰
                        ; If less than 80, go to the next row and run the horizontal loop again

    ; ์‚ฌ๊ฐํ˜• ๊ทธ๋ฆฌ๊ธฐ๊ฐ€ ๋๋‚˜๋ฉด ๋ฌดํ•œ ๋ฃจํ”„๋กœ ๋Œ€๊ธฐ
    ; Infinite loop waiting after rectangle drawing is finished
    jmp $

Leave a Reply