โ๏ธ sector2.asm
— ๋๋ฒ์งธ ์นํฐ / Second sector
[org 0x8000]
1)์ปดํ์ผ๋ฌ๋ ์ด ๊ฐ์ ๊ธฐ์ค์ผ๋ก ๋ชจ๋ ๋ฌธ์์ด ์ฃผ์(์: msg_next_sector)์ ์์น๋ฅผ ๊ณ์ฐํฉ๋๋ค.
The compiler calculates the locations of all string addresses (e.g., msg_next_sector) based on this value.
2)PC๊ฐ ์ฒ์ ๋ถํ
๋์์ ๋, 16๋นํธ ๋ฆฌ์ผ ๋ชจ๋์์ ์ฌ์ฉํ ์ ์๋ ๊ธฐ๋ณธ ๋ฉ๋ชจ๋ฆฌ ๋งต(์ฝ 640KB) ์ค ์ฌ์ฉ์๊ฐ ๋ง์๋๋ก ์ธ ์ ์๋ ์์ ํ ๊ตฌ๊ฐ์ด ์กด์ฌํฉ๋๋ค.
When a PC first boots up, there is a safe region within the base memory map (approximately 640 KB) available in 16-bit real mode that the user can utilize freely.
3)๊ทธ๋์ ์ฃผ์๋ฅผ 0x9000์ผ๋ก ๋ฐ๊ฟ ์ ์์ต๋๋ค.
So, you can change the address to 0x9000.
0x0000 ~ 0x04FF:
BIOS ์ธํฐ๋ฝํธ ๋ฒกํฐ ํ
์ด๋ธ, BIOS ๋ฐ์ดํฐ ์์ญ (์ ๋ ๊ฑด๋๋ฆฌ๋ฉด ์ ๋จ)
BIOS Interrupt Vector Table, BIOS Data Area (must absolutely not be touched)
0x7C00 ~ 0x7DFF:
MBR ์ฝ๋๊ฐ ๋ก๋๋๋ ์์ญ (512๋ฐ์ดํธ)
The area where the MBR code is loaded (512 bytes)
0x7E00 ~ 0x9FFFF:
๋น์ด ์๋ ์ผ๋ฐ ๋ฉ๋ชจ๋ฆฌ ์์ญ (์์ ๋กญ๊ฒ ์ฌ์ฉ ๊ฐ๋ฅ)
Unused general memory area (available for free use)
— 16๋นํธ ๋ฆฌ์ผ๋ชจ๋ / 16bit real mode
bits 16
— mov si, msg_boot ์ฌ๊ธฐ si๋ ์ง์คํฐ์ msg_next_sector์ ์ ์ฅ๋ ๊ฐ์ ์ฃผ์๋ฅผ ์ ์ฅํฉ๋๋ค.mov si, msg_boot: This stores the address of the value held in msg_next_sector into the si register.
mov si, msg_next_sector
— print_string๋ผ๋ฒจ ํจ์ ํธ์ถ์
๋๋ค.
This is a call to the print_string_label function.
call print_string
— ๋๊ธฐ๋ชจ๋์
๋๋ค.(์๊ธฐ ์์ ์ ์์น๋ก ์ ํํฉ๋๋ค.)
It is in standby mode. (It jumps to its own position.)
jmp $
— ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅ๋ ๋ฌธ์์ด์ ํ ๊ธ์์ฉ ์ฝ์ด์, ํ๋ฉด์ ์ฐ์์ผ๋ก ์ถ๋ ฅํ๋ ํจ์์
๋๋ค.
This function reads a string stored in memory character by character and outputs it to the screen continuously.
print_string:
lodsb
cmp al, 0
je .done
mov ah, 0x0e
int 0x10
jmp print_string
.done:
ret
— ๋ณ์๋ฅผ ์ ์ธ๋ถ๋ถ์
๋๋ค.
This is the section where variables are declared.
1)๊ฐ ๋ณ์์ ๋ฌธ์๋ฅผ 1๋ฐ์ดํธ์ฉ ์ ์ฅํฉ๋๋ค.
Store one byte of character data in each variable.
2)13์ ์บ๋ฆฌ์ง ๋ฆฌํด(\r)์ผ๋ก ์ปค์๋ฅผ ํ์ฌ ์ค์ ๋งจ ์ผ์ชฝ(์ฒซ ๋ฒ์งธ ์นธ)์ผ๋ก ์ด๋์ํต๋๋ค.
13 is the carriage return (\r), which moves the cursor to the far left (the first column) of the current line.
3)10 ๋ผ์ธ ํผ๋(\n)๋ก ์ปค์๋ฅผ ํ์ฌ ์์น์์ ์ ํํ ํ ์ค ์๋๋ก ๋ด๋ฆฝ๋๋ค.
10 Moves the cursor exactly one line down from its current position using a line feed (\n).
msg_next_sector db '3. Hello from Sector 2 (0x8000)!', 13, 10, 0
— ๊ณ์ฐ๋ ํ์๋งํผ ๋ฐ์ดํธ(db) ๊ณต๊ฐ์ ์ ๋ถ 0์ผ๋ก ์ฑ์ฐ๋ผ๋ ๋ช
๋ น์ด์
๋๋ค.
This command fills the specified number of bytes (db) with zeros.
1)๋ถํ
ํ๋ณ์ ์ํ ์๊ทธ๋์ฒ๊ฐ ํ์ ์๊ธฐ ๋๋ฌธ์ 512์
๋๋ค.
It is 512 because no signature is required to determine the boot status.
times 512 - ($ - $$) db 0