๐๏ธ ์ด๋ฒ์๋ ๊ฐ๋จํ ๋ช
๋ น์ด๋ฅผ ์
๋ ฅ๋ฐ๊ณ ์คํํ ์ ์๋ ์์ ๋ง๋ค์ด๋ด
์๋ค.
Now, let’s create a shell that can accept and execute simple commands.
๐๏ธ boot.asm์ ๊ธฐ์กด ์ฝ๋์ ๊ฐ์ต๋๋ค.
boot.asm is the same as the existing code.
๐๏ธ ์ ์ฒดํ์ผ์ boot.asm๊ณผ sector2.asm์
๋๋ค.
The complete files are boot.asm and sector2.asm.
๐๏ธ ์ ์ฒด์ฝ๋ / Full Code(secotor2.asm)
[org 0x8000]
bits 16
start:
; ์ฐ์ปด ๋ฉ์์ง ์ถ๋ ฅ
; Print welcome message
mov si, msg_welcome
call print_string
; ํ๋กฌํํธ(miniOS> )๋ฅผ ์ถ๋ ฅํ๊ณ ์
๋ ฅ์ ์ค๋นํ๋ ๊ณณ
; The place to print the prompt (miniOS> ) and prepare for input
prompt:
mov si, msg_prompt
call print_string
; ์
๋ ฅ ๋ฒํผ๋ฅผ ๊ฐ๋ฆฌํฌ ํฌ์ธํฐ(DI)๋ฅผ ๋ฒํผ์ ์์ ์ฃผ์๋ก ์ด๊ธฐํ
; Initialize the pointer (DI) pointing to the input buffer with the starting address of the buffer
mov di, cmd_buffer
mov cx, 0 ; ์
๋ ฅ๋ ๊ธ์ ์๋ฅผ ์ธ๊ธฐ ์ํ ์นด์ดํฐ
; Counter to count the number of entered characters
; ํค๋ณด๋ ์
๋ ฅ์ ํ ๊ธ์์ฉ ๋ฐ๋ ๋ฃจํ
; A loop that receives keyboard input character by character
key_loop:
mov ah, 0x00
int 0x16 ; ํค๋ณด๋ ์
๋ ฅ ๋ฐ๊ธฐ (AL์ ASCII ์ฝ๋ ์ ์ฅ)
; Get keyboard input (Store ASCII code in AL)
; ์ํฐ ํค(13)๋ฅผ ๋๋ ๋์ง ํ์ธ
; Check if the Enter key (13) was pressed
cmp al, 13
je check_command
; ๋ฐฑ์คํ์ด์ค ํค(8) ์ฒ๋ฆฌ (๊ธ์ ์ง์ฐ๊ธฐ)
; Process Backspace key (8) (Erase character)
cmp al, 8
je backspace
; ๋ฒํผ ๋์นจ ๋ฐฉ์ง (์ต๋ 15๊ธ์๋ง ์
๋ ฅ ๊ฐ๋ฅ)
; Prevent buffer overflow (Max 15 characters allowed)
cmp cx, 15
je key_loop
; ํ๋ฉด์ ๊ธ์ ์ถ๋ ฅ (์์ฝ)
; Output character to screen (Echo)
mov ah, 0x0e
int 0x10
; ์
๋ ฅ๋ฐ์ ๋ฌธ์๋ฅผ ๋ฒํผ์ ์ ์ฅํ๊ณ ํฌ์ธํฐ(DI) ์ด๋
; Save the received character to the buffer and move the pointer (DI)
mov [di], al
inc di
inc cx ; ๊ธ์ ์ ์ฆ๊ฐ
; Increment character count
jmp key_loop
; ๋ฐฑ์คํ์ด์ค ์ฒ๋ฆฌ ๋ฃจํด
; Backspace processing routine
backspace:
cmp cx, 0 ; ์
๋ ฅ๋ ๊ธ์๊ฐ ์์ผ๋ฉด ๋ฌด์
; Ignore if no characters are entered
je key_loop
; ํ๋ฉด์์ ๊ธ์ ์ง์ฐ๊ธฐ (์ผ์ชฝ ์ด๋ -> ๊ณต๋ฐฑ ์ถ๋ ฅ -> ๋ค์ ์ผ์ชฝ ์ด๋)
; Erase character from screen (Move left -> Output space -> Move left again)
mov ah, 0x0e
mov al, 8
int 0x10
mov al, ' '
int 0x10
mov al, 8
int 0x10
dec di ; ๋ฒํผ ํฌ์ธํฐ 1 ๊ฐ์
; Decrement buffer pointer by 1
dec cx ; ๊ธ์ ์ 1 ๊ฐ์
; Decrement character count by 1
jmp key_loop
; ์ํฐ๋ฅผ ์ณค์ ๋ ์
๋ ฅ๋ ๋ช
๋ น์ด๋ฅผ ๋น๊ตํ๋ ๊ณณ
; The place to compare the entered command when Enter is pressed
check_command:
; ๋ฌธ์์ด์ ๋์ ํ์ํ๊ธฐ ์ํด ๋ฒํผ์ ํ์ฌ ์์น์ 0(Null) ์ฝ์
; Insert 0 (Null) at the current location of the buffer to mark the end of the string
mov byte [di], 0
; ์ค๋ฐ๊ฟ ์ถ๋ ฅ
; Output newline
call print_newline
; ์
๋ ฅ๋ ๊ธ์๊ฐ ์์ ์์ผ๋ฉด ๊ทธ๋ฅ ๋ค์ ํ๋กฌํํธ๋ก
; If no characters are entered at all, just go to the next prompt
cmp cx, 0
je prompt
; 1. 'help' ๋ช
๋ น์ด ๋น๊ต
; 1. Compare 'help' command
mov si, cmd_buffer
mov di, cmd_help
call compare_string
je do_help ; ๊ฐ์ผ๋ฉด do_help๋ก ์ ํ
; If equal, jump to do_help
; 2. 'clear' ๋ช
๋ น์ด ๋น๊ต
; 2. Compare 'clear' command
mov si, cmd_buffer
mov di, cmd_clear
call compare_string
je do_clear ; ๊ฐ์ผ๋ฉด do_clear๋ก ์ ํ
; If equal, jump to do_clear
; ์ผ์นํ๋ ๋ช
๋ น์ด๊ฐ ์์ผ๋ฉด ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅ
; If no matching command is found, print error message
mov si, msg_unknown
call print_string
jmp prompt
; [๋ช
๋ น์ด ์ฒ๋ฆฌ] help ๊ตฌํ
; [Command Processing] Implement help
do_help:
mov si, msg_help_text
call print_string
jmp prompt
; [๋ช
๋ น์ด ์ฒ๋ฆฌ] clear ๊ตฌํ
; [Command Processing] Implement clear
do_clear:
; BIOS ํ๋ฉด ์คํฌ๋กค ๊ธฐ๋ฅ์ ์ด์ฉํด ํ๋ฉด ์ง์ฐ๊ธฐ
; Clear screen using BIOS screen scroll function
mov ah, 0x06 ; ์คํฌ๋กค ์
๊ธฐ๋ฅ
; Scroll up function
mov al, 0 ; 0 = ํ๋ฉด ์ ์ฒด ์ง์ฐ๊ธฐ
; 0 = Clear entire screen
mov bh, 0x07 ; ๋ฐํ์ ๊ฒ์ , ๊ธ์์ ํฐ์
; Background black, Foreground white
mov ch, 0 ; ์ข์๋จ ํ
; Upper left row
mov cl, 0 ; ์ข์๋จ ์ด
; Upper left column
mov dh, 24 ; ์ฐํ๋จ ํ
; Lower right row
mov dl, 79 ; ์ฐํ๋จ ๅ
; Lower right column
int 0x10
; ์ปค์๋ฅผ ๋งจ ์ ์ข์๋จ(0,0)์ผ๋ก ์ด๋
; Move cursor to the top-left corner (0,0)
mov ah, 0x02
mov bh, 0
mov dh, 0
mov dl, 0
int 0x10
jmp prompt
; [ํจ์] ๋ ๋ฌธ์์ด์ด ๊ฐ์์ง ๋น๊ต (SI์ DI ์ฃผ์์ ๋ฌธ์์ด ๋น๊ต)
; [Function] Compare if two strings are equal (Compare strings at SI and DI addresses)
compare_string:
.loop:
mov al, [si]
mov bl, [di]
cmp al, bl ; ๋ ๊ธ์๊ฐ ๊ฐ์์ง ๋น๊ต
; Compare if two characters are equal
jne .not_equal ; ๋ค๋ฅด๋ฉด ํ์ถ
; If not equal, escape
cmp al, 0 ; ๋ฌธ์์ด์ด ๋๋ฌ๋์ง ํ์ธ (๋ ๋ค 0์ธ ์ํฉ)
; Check if the string ended (Both are 0 case)
je .equal ; ๋๋ฌ์ผ๋ฉด ์๋ฒฝํ ์ผ์น
; If ended, perfect match
inc si
inc di
jmp .loop
.not_equal:
clc ; Carry Flag ํด๋ฆฌ์ด (๊ฐ์ง ์์ ํ์, ์ต์ง flag ์ธํ
์ฉ์ผ๋ก cmp ํ์ฉ)
; Clear Carry Flag (Indicate not equal, use cmp for forced flag setting)
mov al, 1
cmp al, 0 ; Zero Flag๋ฅผ 0์ผ๋ก ๋ง๋ค์ด '๋ค๋ฆ'์ ์๋ฆผ
; Set Zero Flag to 0 to notify 'Not Equal'
ret
.equal:
cmp al, 0 ; Zero Flag๋ฅผ 1๋ก ๋ง๋ค์ด '๊ฐ์'์ ์๋ฆผ (AL์ด 0์ด๋ฏ๋ก)
; Set Zero Flag to 1 to notify 'Equal' (Since AL is 0)
ret
; [ํจ์] ๋ฌธ์์ด ์ถ๋ ฅ
; [Function] Print string
print_string:
lodsb
cmp al, 0
je .done
mov ah, 0x0e
int 0x10
jmp print_string
.done:
ret
; [ํจ์] ์ค๋ฐ๊ฟ ์ถ๋ ฅ
; [Function] Print newline
print_newline:
mov ah, 0x0e
mov al, 13
int 0x10
mov al, 10
int 0x10
ret
; ----------------------------------------------------
; ๋ฐ์ดํฐ ๋ฐ ๋ณ์ ์ ์ธ ์์ญ (์ ์ญ ๋ณ์)
; Data and variable declaration area (Global variables)
; ----------------------------------------------------
msg_welcome db '3. Hello from Sector 2! miniOS Shell Started.', 13, 10, 0
msg_prompt db 'miniOS> ', 0
msg_unknown db 'Unknown command! Type "help".', 13, 10, 0
msg_help_text db 'Available commands: help, clear', 13, 10, 0
; ๋น๊ตํ ๋ช
๋ น์ด ๊ธฐ์ค ๋ฌธ์์ด (์์)
; Reference command strings for comparison (Constants)
cmd_help db 'help', 0
cmd_clear db 'clear', 0
; ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ๊ธ์๋ค์ ๋ด์ '๋น ๋ณ์ ๊ณต๊ฐ' (๋ฒํผ)
; 'Empty variable space' to hold characters entered by the user (Buffer)
; 16๋ฐ์ดํธ ํฌ๊ธฐ๋งํผ ๊ณต๊ฐ์ ๋ฏธ๋ฆฌ ํ๋ณดํด ๋ก๋๋ค.
; Pre-allocate space of 16 bytes.
cmd_buffer times 16 db 0
; 512๋ฐ์ดํธ ํฌ๊ธฐ ๋ง์ถ๊ธฐ
; Fill up to 512 bytes
times 512 - ($ - $$) db 0
๐๏ธ ์ฝ๋์ค๋ช (sector2.asm)
โ๏ธ boot.asm ์ฝ๋์ค๋ช
์ ์ด์ ๊ณผ ๊ฐ์์ ์๋ตํฉ๋๋ค.
I will skip the explanation of the boot.asm code, as it is the same as before.
โ๏ธ ๋ฉ์ธ์ง ์ถ๋ ฅ๋ฑ ์ด์ ๊ณผ ๊ตฌ์กฐ๊ฐ์ ๋ถ๋ถ์ ์ค๋ช
์ ์๋ตํฉ๋๋ค.
Explanations regarding aspects where the structure remains the same as beforeโsuch as message outputโare omitted.
โ๏ธ ์ ์ฅํ ๋ชฉ์ ์ง ์ฃผ์ ์ง์ (prompt:)
Specify destination address to save (prompt:)
— DI (Destination Index) ๋ ์ง์คํฐ๋ CPU๊ฐ ๋ฉ๋ชจ๋ฆฌ์ ๋ฐ์ดํฐ๋ฅผ ‘์ ์ฅ(๊ธฐ๋ก)’ํ ๋ ์ฃผ๋ก ์ฌ์ฉํ๋ ๋ํ์ ์ธ ํฌ์ธํฐ(ํ์ดํ) ๋ ์ง์คํฐ์
๋๋ค.
The DI (Destination Index) register is a representative pointer register primarily used by the CPU when storing (writing) data to memory.
— cmd_buffer:
์ถ๋ฐ์ (0x8000)์์ ์ฝ๋ ๊ธธ์ด๋งํผ ๋ค๋ก ๋จ์ด์ง ๋ฒํผ ์ ์ฉ ๋ฐฉ ๋ฒํธ(์ค์ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์)์
๋๋ค.
This is the buffer-specific room number (actual memory address) located a distance equal to the code length behind the starting point (0x8000).
— ์๋์์ mov [di], al ์ด๋ ๊ฒ ์ฌ์ฉํฉ๋๋ค.
Below, it is used like this: mov [di], al.
mov di, cmd_buffer
โ๏ธ ์
๋ ฅํ ๊ธ์ ์ ์ธ๋ ์นด์ดํฐ
Counter that counts the number of characters entered
mov cx, 0
โ๏ธ ํค๋ณด๋ ์
๋ ฅ์ ํ ๊ธ์์ฉ ๋ฐ๋ ๋ฃจํ(key_loop:)
A loop that accepts keyboard input one character at a time (key_loop:)
— ํค๋ณด๋ ์
๋ ฅ ์ฝ๊ธฐ ๊ธฐ๋ฅ ์ ํ (๋ฐ์ด์ค์ค ์๋น์ค ์ธํฐ๋ฝํธ)
Select Keyboard Input Read Function (BIOS Service Interrupt)
mov ah, 0x00
— ์ธํฐ๋ฝํธ ์คํ
Interrupt execution
— AH = 0x00 ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ BIOS ํค๋ณด๋ ์ธํฐ๋ฝํธ๋ฅผ ์ต์ข
ํธ์ถํฉ๋๋ค.
Finally, the BIOS keyboard interrupt is called with AH = 0x00.
— ํ๋ฉด ์ถ๋ ฅ(int 0x10), ๋์คํฌ ์ฝ๊ธฐ(int 0x13), ํค๋ณด๋ ์
๋ ฅ(int 0x16)
Screen output (int 0x10), disk read (int 0x13), keyboard input (int 0x16)
— ์ฌ์ฉ์์
๋ ฅ์ ๋ฐ๊ธฐ ์ํด ๋ธ๋กํน ์ํ๊ฐ ๋ฉ๋๋ค.
It enters a blocking state to receive user input.
int 0x16
— ์ํฐํค๊ฐ ์
๋ ฅ๋๋ฉด check_command๋ผ๋ฒจ์ ์คํ ํฉ๋๋ค.
When the Enter key is pressed, the check_command label is executed.
cmp al, 13
je check_command
— ๋ฐฑ์คํ์ด์ค ํค๋ฅผ ์
๋ ฅ์ backspace๋ผ๋ฒจ์ ์คํํฉ๋๋ค.
Pressing the Backspace key executes the ‘backspace’ label.
cmp al, 8
je backspace
— ๋ฒํผ ์ค๋ฒํ๋ก์ฐ ๋ฐฉ์ง ๊ธฐ๋ฅ ์
๋๋ค.
This is a buffer overflow prevention feature.
— ์ฌ์ฉ์๊ฐ ํค๋ณด๋๋ฅผ ํ ๊ธ์์ฉ ์น ๋๋ง๋ค inc cx ๋ช
๋ น์ด๋ฅผ ํตํด ํ์ฌ ๋ฒํผ์ ์์ธ ๊ธ์ ์๋ฅผ ๊ธฐ์ตํ๊ณ ์์ต๋๋ค.
Each time the user types a character, the inc cx instruction tracks the number of characters accumulated in the current buffer.
— cmp (Compare) ๋ช
๋ น์ด๋ฅผ ํตํด “ํ์ฌ ๊ธ์ ์(CX)๊ฐ 15์ ๊ฐ์์ง” ๋น๊ตํฉ๋๋ค.
The cmp (Compare) instruction is used to compare whether the current character count (CX) is equal to 15.
— cmd_buffer์ ํฌ๊ธฐ๋ 16๋ฐ์ดํธ์ด๋ฉฐ ๋ง์ง๋ง์ ์ข
๋ฃํ์ ์ ํธ 0์ด๋ค์ด๊ฐ๋ฏ๋ก ๊ธ์์๋ฅผ 15๋ฐ์ดํธ๊น์ง๋ก ์ ํํฉ๋๋ค.
The size of cmd_buffer is 16 bytes; since a null terminator (0) is placed at the end, the character count is limited to 15 bytes.
— 15์๋ฅผ ์ด๊ณผํ๋ฉด key_loop๋ผ๋ฒจ๋ก ์ ํํฉ๋๋ค.
If it exceeds 15 characters, it jumps to the key_loop label.
— ์ถ๊ฐ ์
๋ ฅํ๋ฉด ํ๋ฉด์์๋ ๊ณ์ ๊ฐ์์๋ฆฌ์ ์ปค์๊ฐ ์๊ณ ๋ณํ๊ฐ ์์ต๋๋ค.
If you enter more input, the cursor remains in the same position on the screen, and there is no change.
cmp cx, 15
je key_loop
— ํ๋ฉด์ ๊ธ์๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
It outputs text to the screen.
mov ah, 0x0e
int 0x10
— ์ฌ์ฉ์๊ฐ ๋๋ฅธ ๊ธ์๊ฐ ์ ์ฅ๋ al๋ ์ง์คํฐ์ ๋ด์ฉ์ cmd_buffer์ ์ ์ฅํฉ๋๋ค.
The contents of the AL register, which holds the character pressed by the user, are stored in cmd_buffer.
mov [di], al
— ๋ค์ ์ ์ฅ ์์น๋ก ์ด๋ํฉ๋๋ค.
Navigate to the following save location.
— inc (Increment): ๊ฐ์ 1 ์ฆ๊ฐ์ํค๋ ๋ช
๋ น์ด์
๋๋ค.
inc (Increment): An instruction that increments a value by 1.
— DI ๋ ์ง์คํฐ์ ๋ค์ด์๋ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์ ์ซ์๋ฅผ 1 ๋๋ ค์ค๋๋ค. (์: 0x8064 โ 0x8065)
Increments the memory address value stored in the DI register by 1. (e.g., 0x8064 โ 0x8065)
— ์ฃผ์๋ฅผ 1 ๋๋ ค์ฃผ์ด์ผ ๋ค์๋ฒ์ ์ฌ์ฉ์๊ฐ ์๋ก์ด ํค๋ฅผ ๋๋ฅผ ๋, ๋ฐฉ๊ธ ์ด ๊ธ์ ์์ ๊ฒน์ณ ์ฐ์ง ์๊ณ ๊ทธ ๋ฐ๋ก ์ ์นธ(๋ค์ ๋ฐ์ดํธ)์ ์ ๊ธ์๋ฅผ ์ ์ฅํ ์ ์๊ธฐ ๋๋ฌธ์
๋๋ค.
This is because the address must be incremented by 1 so that the next time the user presses a key, the new character can be stored in the adjacent cell (the next byte) instead of overwriting the character just written.
inc di
— ๊ธ์ ์๋ฅผ ์ธ๋ ์นด์ดํฐ๋ฅผ ์ฆ๊ฐ์ํต๋๋ค.
Increments the character count.
inc cx
— ์ฌ๊ธฐ๊น์ง๊ฐ ์ค์ ๋ฉ์ธ ๋ก์ง์
๋๋ค.
This covers the actual main logic.
โ๏ธ ๋ฐฑ์คํ์ด์ค ์ฒ๋ฆฌ๋ฃจํด(backspace:)
Backspace handling routine (backspace:)
— ์
๋ ฅ๋ ๊ธ์๊ฐ 0์ธ์ง ํ์ธํฉ๋๋ค. ์
๋ ฅ๋ ๊ธ์๊ฐ ์๋๋ฐ ๋ฐฑ์คํ์ด์ค ํค๋ฅผ ๋๋ฅธ๊ฒฝ์ฐ key_loop๋ผ๋ฒจ(ํค๋ณด๋ ์
๋ ฅ๋ฐ๊ธฐ)๋ก ์ ํํฉ๋๋ค.
It checks whether the input string is empty. If the Backspace key is pressed when there is no input, it jumps to the key_loop label (to receive keyboard input).
cmp cx, 0
je key_loop
— ํ๋ฉด์์ ๊ธ์๋ฅผ ์ง์ฐ๋ ๋ถ๋ถ์
๋๋ค.
This is the part where text is erased from the screen.
— ์ปดํจํฐ ๋ด๋ถ์ ํ๋ฉด ์ ์ด ์์คํ
(BIOS)์๋ ‘๋ฐฉ๊ธ ์ด ๊ธ์๋ฅผ ์ง์ฐ๋ ํธ๋ฆฌํ ์ญ์ ๊ธฐ๋ฅ’์ด ๋ฐ๋ก ์์ต๋๋ค. ์ค์ง ์๋ก์ด ๊ธ์๋ฅผ ์์ ๋ฎ์ด์ฐ๋ ๊ธฐ๋ฅ๋ง ์์ต๋๋ค.
The screen control system (BIOS) inside the computer does not have a dedicated, convenient delete function for erasing the characters just written; it only has a function to overwrite them with new characters.
— ๋ฐ๋ผ์ ๊ธ์๋ฅผ ์ง์ฐ๋ ค๋ฉด “์ง์ฐ๊ณ ์ถ์ ์์น๋ก ์ปค์๋ฅผ ์ฎ๊ธด ๋ค, ‘๊ณต๋ฐฑ(์คํ์ด์ค๋ฐ)’ ๋ฌธ์๋ฅผ ๊ฐ์ ๋ก ๋ฎ์ด์จ์ ๊ธ์๋ฅผ ์ ๋ณด์ด๊ฒ ๊ฐ๋ฆฝ๋๋ค.
Therefore, to erase a character, move the cursor to the desired position and overwrite the character with a space (using the spacebar) to hide it from view.
— ๋ฐ์ด์ค์ค ํ
๋ ๊ทธ๋ํ ๊ธฐ๋ฅ์ ์ ํํฉ๋๋ค.
Select the BIOS Telegraph function.
mov ah, 0x0e
— al๋ ์ง์คํฐ์ 8์ ๋์
ํฉ๋๋ค.ASCII ์ฝ๋ 8๋ฒ์ ‘๋ฐฑ์คํ์ด์ค(Backspace)’ ๋ฌธ์์
๋๋ค.
Assign 8 to the AL register. ASCII code 8 represents the ‘Backspace’ character.
— int 0x10๋ก BIOS ๋น๋์ค ์ธํฐ๋ฝํธ๋ฅผ ์คํํฉ๋๋ค.(๊ธฐ๋ฅ ์คํ)
Executes the BIOS video interrupt using int 0x10 (executes the function).
mov al, 8
int 0x10
— ํ์ฌ์์น๋ฅผ ๊ณต๋ฐฑ์ผ๋ก ๋ฐ๊ฟ๋๋ค.
Changes the current location to a blank space.
mov al, ' '
int 0x10
— ์ผ์ชฝ์ผ๋ก ์ปค์๋ฅผ ํ์นธ ์ฎ๊น๋๋ค.
Moves the cursor one space to the left.
mov al, 8
int 0x10
— ๋ฒํผ๋ฉ๋ชจ๋ฆฌ(di)๋ฅผ 1 ๊ฐ์ํ๊ณ , ๊ธ์์ ์นด์ดํฐ๋ฅผ 1๊ฐ์ํฉ๋๋ค.
Decrement the buffer memory (di) by 1 and decrement the character count counter by 1.
— key_loop๋ผ๋ฒจ๋ก ์ ํํฉ๋๋ค.
Jump to the key_loop label.
dec di
dec cx
jmp key_loop
โ๏ธ ์ํฐ๋ฅผ ์ณค์ ๋ ์
๋ ฅ๋ ๋ช
๋ น์ด๋ฅผ ๋น๊ตํ๋ ๊ณณ
The place where the entered command is compared when the Enter key is pressed.
— ํ์ฌ ์์น์ 0์ ์
๋ ฅํด์ ๋ช
๋ น์ด์ ๋์์ ํ์ํฉ๋๋ค.
Enter 0 at the current position to indicate the end of the command.
— DI ์ฃผ์๊ฐ ๊ฐ๋ฆฌํค๋ ๊ณณ์ ๋ฑ 1๋ฐ์ดํธ ํฌ๊ธฐ๋งํผ๋ง 0์ ๋์
ํ๋ผ๋ ํฌ๊ธฐ ์ง์ ํค์๋ ์
๋๋ค.
This is a size-specifying keyword that instructs to assign a zero value of exactly one byte in size to the location pointed to by the DI register.
byte: 1๋ฐ์ดํธ ํฌ๊ธฐ (8๋นํธ) / 1-byte size (8 bits) โ mov byte [di],
word: 2๋ฐ์ดํธ ํฌ๊ธฐ (16๋นํธ) / 2-byte size (16-bit) โ mov word [di], 0
dword: 4๋ฐ์ดํธ ํฌ๊ธฐ / 4-byte size (32๋นํธ/32 bit, Double Word) โ mov dword [di], 0
mov byte [di], 0
— ์ค ๋ฐ๊ฟ์ ์คํํฉ๋๋ค.
Performs a line break.
call print_newline
— ์๋์ print_newline:๋ผ๋ฒจ์ด ์์ต๋๋ค.
There is a print_newline: label below.
— mov ah, 0x0e :
ํ
๋ ํ์ดํ ๋ฐฉ์ ์ถ๋ ฅ์ ์ค์ ํฉ๋๋ค.
Configures teletype-style output.
— mov al, 13 & int 0x10
ํ์ฌ ์์นํ ์ค์ ๋งจ ์ผ์ชฝ(์ฒซ ๋ฒ์งธ ์นธ)์ผ๋ก ์ด๋ ํฉ๋๋ค.(์ผ๋ฆฌ์ง๋ฆฌํด,\r)
Moves to the leftmost position (the first cell) of the current line (Carriage Return, \r).
–mov al, 10 & int 0x10 :
์ปค์๋ฅผ ํ ์ค ์๋๋ก ์ด๋์ํต๋๋ค.(๋ผ์ธํผ๋,\n)
Moves the cursor down one line (Line Feed, \n).
— ref
์ด ํจ์๋ฅผ ํธ์ถํ๋ ๋ฉ์ธ ๋ก์ง์ ์๋ฆฌ๋ก ์ด๋ํฉ๋๋ค.
Navigate to the location in the main logic where this function was called.
print_newline:
mov ah, 0x0e
mov al, 13
int 0x10
mov al, 10
int 0x10
ret
๐๐ป ์คํฌ๋ฆฐ ์ท / ScreenShot


โ
๋๋จธ์ง ์ค๋ช
์ ๋ค์ ํฌ์คํธ์์์ด์ด๊ฐ๊ฒ ์ต๋๋ค.
I will continue with the rest of the explanation in the next post.