๋์คํฌ์์ ์ถ๊ฐ ๋ฐ์ดํฐ ๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์ค๋ช
์
๋๋ค.
This explains how to load additional data from the disk.
๐๏ธ ๋์คํฌ๋ ํ๋กํผ ๋์คํฌ์
๋๋ค.
The disk is a floppy disk.
๐๏ธ ์ ์ฒด์ฝ๋(NASM) / Full Code(NASM)
โ๏ธ boot.asm
— ์ฒซ ๋ฒ์งธ ์นํฐ(512๋ฐ์ดํธ)๋ง ๋ด๋นํ๋ ์ฝ๋์
๋๋ค.
This code handles only the first sector (512 bytes).
[org 0x7c00]
bits 16
start:
mov ax, 0
mov ds, ax
mov es, ax
mov si, msg_boot
call print_string
; ๋์คํฌ ์ฝ๊ธฐ (2๋ฒ ์นํฐ๋ถํฐ 1๊ฐ ์นํฐ๋ฅผ 0x8000์ ๋ก๋)
; Disk read (load 1 sector starting from sector 2 to 0x8000)
mov ah, 0x02
mov al, 1
mov ch, 0
mov cl, 2
mov dh, 0
mov bx, 0x8000
int 0x13
jc disk_error
mov si, msg_success
call print_string
; ๋ก๋๋ 2๋ฒ ์นํฐ ์ฝ๋๋ก ์ ํ
; Jump to loaded sector 2 code
jmp 0x8000
disk_error:
mov si, msg_error
call print_string
jmp hang
hang:
jmp $
print_string:
lodsb
cmp al, 0
je .done
mov ah, 0x0e
int 0x10
jmp print_string
.done:
ret
msg_boot db '1. Booting MBR...', 13, 10, 0
msg_success db '2. Disk read success!', 13, 10, 0
msg_error db 'Disk read failed!', 13, 10, 0
times 510 - ($ - $$) db 0
dw 0xaa55
— ๋ฉ๋ชจ๋ฆฌ 0x8000์ ๋ก๋๋์ด ์คํ๋ ๋
๋ฆฝ๋ ์ฝ๋ ํ์ผ์
๋๋ค. ๋๊ฐ์ด 512๋ฐ์ดํธ ํฌ๊ธฐ๋ฅผ ๋ง์ถฐ์ค๋๋ค.
This is a standalone code file designed to be loaded into memory at address 0x8000 and executed. It is also sized to exactly 512 bytes.
[org 0x8000]
bits 16
start:
mov si, msg_next_sector
call print_string
; ๋๊ธฐ๋ชจ๋ / Standby mode
jmp $
print_string:
lodsb
cmp al, 0
je .done
mov ah, 0x0e
int 0x10
jmp print_string
.done:
ret
msg_next_sector db '3. Hello from Sector 2 (0x8000)!', 13, 10, 0
times 512 - ($ - $$) db 0
๐๏ธ์ปดํ์ผ ๋ฐ ์คํ ๋ฐฉ๋ฒ (QEMU ๊ธฐ์ค)
How to compile and run (using QEMU)
โ๏ธ Xubuntu ํฐ๋ฏธ๋์์ ๋ค์ ๋ช
๋ น์ด๋ฅผ ์์๋๋ก ์คํํฉ๋๋ค.
Run the following commands in order in the Xubuntu terminal.
โ๏ธ ๋ ์ฝ๋๋ฅผ ๊ฐ๊ฐ ๋น๋ํ ๋ค ๋ฆฌ๋
์ค์ cat๊ณผ dd ๋ช
๋ น์ด๋ก ์๋ฒฝํ ๊ฐ์ ๋์คํฌ ์ด๋ฏธ์ง๋ฅผ ๋ง๋ญ๋๋ค.
After building each piece of code, create a complete virtual disk image using the Linux cat and dd commands.
# 1. ๊ฐ๊ฐ์ ์ด์
๋ธ๋ฆฌ ํ์ผ์ ๋ฐ์ด๋๋ฆฌ๋ก ์ปดํ์ผ
# Compile each assembly file into binary
nasm -f bin boot.asm -o boot.bin
nasm -f bin sector2.asm -o sector2.bin
# 2. ๋ ํ์ผ์ ํ๋๋ก ํฉ์นจ (์ด 1024๋ฐ์ดํธ)
# Merged two files into one (total 1,024 bytes)
cat boot.bin sector2.bin > temp.bin
# 3. ๊ฐ์ ๋จธ์ BIOS๊ฐ ์ค์ธํ์ง ์๋๋ก 1.44MB ํ๋กํผ ๋์คํฌ ๊ท๊ฒฉ์ผ๋ก ๋น ๊ณต๊ฐ ์ฑ์ฐ๊ธฐ
# Pad the empty space to the 1.44MB floppy disk specification
# to prevent the virtual machine BIOS from misinterpreting it.
dd if=temp.bin of=os.img bs=512 count=2880 conv=sync
# 4. QEMU ์คํ
# Run QEMU
qemu-system-x86_64 -drive file=os.img,format=raw,if=floppy -boot a
๐๏ธ์ฝ๋ ์ค๋ช / Code Explanation
โ๏ธ boot.asm
— ๋ ์ง์คํฐ๋ฅผ 0์ผ๋ก ์ด๊ธฐํ ํฉ๋๋ค.
Initialize the register to zero.
mov ax, 0
mov ds, ax
mov es, ax
1) ์ธ๊ทธ๋จผํธ ๋ ์ง์คํฐ๋ ์ง์ ๊ฐ์ ๋์
ํ ์ ์์ต๋๋ค.
You cannot directly assign values โโto segment registers.
2) ๊ทธ๋์ ๋ฒ์ฉ๋ ์ง์คํฐ์ 0์ ๋์
ํ๊ณ ์ด ๋ฒ์ฉ ๋ ์ง์คํฐ๋ฅผ ์ธ๊ทธ๋จผํธ๋ ์ง์คํฐ์ ๋ค์ ๋์
ํฉ๋๋ค.
So, we assign 0 to a general-purpose register and then assign that register to a segment register.
๐16๋นํธ ์ปดํจํฐ ์ธ๊ทธ๋จผํธ๋ ์ง์คํฐ / 16-bit computer segment register
ds (Data Segment):
์ฝ๋์์ ์ฌ์ฉํ ๋ฌธ์์ด, ๋ณ์ ๋ฑ์ ๋ฐ์ดํฐ ์ฃผ์ ๊ธฐ์ค์ ์ ๊ฐ๋ฆฌํต๋๋ค.
It points to the reference point for data addressesโsuch as strings and variablesโused in the code.
es (Extra Segment):
๋์คํฌ์์ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์ค๊ฑฐ๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋ณต์ฌํ ๋ ์ฐ๋ ์ถ๊ฐ ๋ชฉ์ ์ง ์ฃผ์ ๊ธฐ์ค์ ์
๋๋ค.
This is an additional destination address reference point used when reading data from a disk or copying memory.
cs (Code Segment):
CPU๊ฐ ์ง๊ธ ์คํํ๊ณ ์๋ ๊ธฐ๊ณ์ด ์ฝ๋์ ์ฃผ์ ๊ธฐ์ค์ ์
๋๋ค.
It is the reference address for the machine code currently being executed by the CPU.
ss (Stack Segment):
ํจ์ ํธ์ถ์ด๋ ์์ ๋ฐ์ดํฐ ์ ์ฅ์ ์ฐ๋ ์คํ ๋ฉ๋ชจ๋ฆฌ์ ์ฃผ์ ๊ธฐ์ค์ ์
๋๋ค
It is the reference address for the stack memory used for function calls or temporary data storage.
— mov si, msg_boot ์ฌ๊ธฐ si๋ ์ง์คํฐ์ msg_boot์ ์ ์ฅ๋ ๊ฐ์ ์ฃผ์๋ฅผ ์ ์ฅํฉ๋๋ค.mov si, msg_boot stores the address of the value held in msg_boot into the si register.
1)msg_boot๋ณ์์๋ msg_boot db ‘1. Booting MBRโฆ’, 13, 10, 0 ์ด๋ ๊ฒ ์ ์ฅ๋์ด ์์ต๋๋ค.
The msg_boot variable stores the following: msg_boot db '1. Booting MBRโฆ', 13, 10, 0.
mov si, msg_boot
— ํจ์๋ฅผ ์คํํฉ๋๋ค.
Executes the function.
1)ํ์ผ ์๋์ print_string: ๋ผ๋ฒจ์ด์์ต๋๋ค.
There is a print_string: label at the bottom of the file.
2) call print_stringํ๋ฉด ๋์์ฌ ์ฃผ์๋ฅผ ์คํ์ ์ ์ฅํ๊ณ ์ ํํฉ๋๋ค.
Calling print_string saves the return address onto the stack and then jumps.
3) ํํ๋ ๋ผ๋ฒจ์ด์ง๋ง ์ด๊ฒ์ ๊ธฐ๋ฅ์ ์ผ๋ก ํจ์๋ผ๊ณ ํฉ๋๋ค.
Although it takes the form of a label, functionally it is referred to as a function.
call print_string
— ๋์คํฌ ์ฝ๊ธฐ / Disk read
1)๋์คํฌ ์นํฐ๋ฅผ ๋ฉ๋ชจ๋ฆฌ๋ก ์ฝ์ด์ค๊ฒ ๋ค(Read Sectors)”๋ ๊ธฐ๋ฅ ๋ฒํธ(0x02)๋ฅผ ์ ํํ๋ ๋ช
๋ น์
๋๋ค.
This is a command to select function number 0x02, which reads disk sectors into memory.
mov ah, 0x02
2)๋์คํฌ์์ ๋ช ๊ฐ์ ์นํฐ๋ฅผ ์ฝ์์ง ์ง์ ํฉ๋๋ค. ์ฌ๊ธฐ์๋ 1 ์นํฐ(512๋ฐ์ดํธ)๋งํผ ์ฝ๊ฒ ๋ค๋ ๋ป์
๋๋ค.
Specifies how many sectors to read from the disk. In this case, it means reading one sector (512 bytes).
mov al, 1
3) (์ค๋ฆฐ๋ ๋ฒํธ)๋์คํฌ ํธ๋์ ์์น๋ฅผ ๋ํ๋ด๋ ์ค๋ฆฐ๋(Cylinder) ๋ฒํธ๋ฅผ 0๋ฒ์ผ๋ก ์ง์ ํฉ๋๋ค. ๋์คํฌ์ ๋งจ ๋ฐ๊นฅ์ชฝ ๊ฐ์ฅ์๋ฆฌ๋ฅผ ๋ปํฉ๋๋ค.
(Cylinder Number) Specifies the cylinder numberโrepresenting the position of the disk trackโas 0. This refers to the outermost edge of the disk.
mov ch, 0
4)(์นํฐ ๋ฒํธ)๋์คํฌ์ ๋ช ๋ฒ์งธ ์นํฐ๋ถํฐ ์ฝ๊ธฐ ์์ํ ์ง ์ง์ ํฉ๋๋ค. ๋ถํธ ๋ก๋(MBR)๊ฐ 1๋ฒ ์นํฐ์ ๋ค์ด์์ผ๋ฏ๋ก, ๊ทธ ๋ฐ๋ก ๋ค์ ์์ญ์ธ 2๋ฒ ์นํฐ๋ฅผ ์ง์ ํ ๊ฒ์
๋๋ค.
(Sector Number) Specifies the starting sector on the disk for the read operation. Since the boot loader (MBR) is located in sector 1, sector 2โthe area immediately following itโhas been specified.
mov cl, 2
5)(ํค๋ ๋ฒํธ)๋์คํฌ์ ์๋ท๋ฉด์ ๊ฒฐ์ ํ๋ ํค๋(Head) ๋ฒํธ๋ฅผ 0๋ฒ์ผ๋ก ์ง์ ํฉ๋๋ค. (๋จ๋ฉด ๋๋ ์ฒซ ๋ฒ์งธ ๋ฉด์ ๋ปํจ)
(Head Number) Specifies the head numberโwhich determines the front or back side of the diskโas 0 (indicating the single side or the first side).
mov dh, 0
6)(์ ์ฅํ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์)๋์คํฌ์์ ์ฝ์ด์จ 512๋ฐ์ดํธ ๋ฐ์ดํฐ๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ๋ช ๋ฒ์ง ์๋ฆฌ์ ์ ์ฅํ ์ง ์ง์ ํ๋ ๋ชฉ์ ์ง ์ฃผ์์
๋๋ค.
(Memory address for storage) This is the destination address specifying where in memory the 512 bytes of data read from the disk should be stored.
์์ ๋ฐ์ดํฐ ์ธ๊ทธ๋จผํธ(ES)๋ฅผ 0์ผ๋ก ์ด๊ธฐํํ์ผ๋ฏ๋ก, ์ค์ ์ ์ฅ ์์น๋ 0x0000:0x8000์ด ๋ฉ๋๋ค.
Since the data segment (ES) was previously initialized to 0, the actual storage location becomes 0x0000:0x8000.
mov bx, 0x8000
7)(์ธํฐ๋ฝํธ ์คํ)์์์ ์ค์ ํ ๋ชจ๋ ๋ ์ง์คํฐ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ BIOS ๋์คํฌ ์ธํฐ๋ฝํธ๋ฅผ ์ต์ข
ํธ์ถ(์คํ)ํฉ๋๋ค.
(Interrupt Execution) The BIOS disk interrupt is finally called (executed) using all the register information configured above.
๋์คํฌ ํ๋์จ์ด๊ฐ ์ด ์ ํธ๋ฅผ ๋ฐ์ ์ง์ ๋ ๋ฐ์ดํฐ๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ๋ณต์ฌํด ๋ฃ์ต๋๋ค.
The disk hardware receives this signal and copies the specified data into memory.
int 0x13
โ
๋ถํธ๋ก๋๊ฐ 1๋ฒ์ธ๊ฒ์ ์ด๋ป๊ฒ ์ ์ ์๋?
How can I tell that the bootloader is number 1?
์ปดํจํฐ ํ๋์จ์ด(CPU์ BIOS)๋ฅผ ๋ง๋ ์ ์กฐ์ฌ๋ค์ด ์ ์ธ๊ณ์ ์ธ ๊ท์น(ํ์ค ๋๋ฐ์ด์ค ๊ท๊ฒฉ)์ผ๋ก ๊ทธ๋ ๊ฒ ์ ํด๋์๊ธฐ ๋๋ฌธ์
๋๋ค.
This is because the manufacturers of computer hardware (CPU and BIOS) established it that way as a global rule (standard device specification).
ํ๋๋์คํฌ, ํ๋กํผ๋์คํฌ, USB ๋ฑ ๋ชจ๋ ๋ถํ
๋งค์ฒด์ ๋งจ ์ฒซ ๋ฒ์งธ ์นธ(1๋ฒ ์นํฐ, 512๋ฐ์ดํธ)์ MBR(๋ง์คํฐ ๋ถํธ ๋ ์ฝ๋) ๋๋ ๋ถํธ ์นํฐ๋ผ๊ณ ๋ถ๋ฆ
๋๋ค.
The very first segment (Sector 1, 512 bytes) of any boot mediumโsuch as a hard disk, floppy disk, or USB driveโis called the MBR (Master Boot Record) or boot sector.
์์คํ
์ด ์ผ์ง ๋ ๋ฉ์ธ๋ณด๋์ BIOS๊ฐ ๋ฌด์กฐ๊ฑด ๋์คํฌ์ ์ฒซ ๋ฒ์งธ ์นํฐ(์ค๋ฆฐ๋ 0, ํค๋ 0, ์นํฐ 1)๋ฅผ ๊ฐ์ฅ ๋จผ์ ์ฝ๋๋ก ์ค๊ณ๋์ด ์๊ธฐ ๋๋ฌธ์
๋๋ค.(๋์คํฌ ์นํฐ ๋ฒํธ๋ 1๋ถํฐ ์์)
This is because the motherboard's BIOS is designed to always read the disk's first sector (cylinder 0, head 0, sector 1) first when the system powers on (disk sector numbering starts at 1).
— ์ค๋ฅ ํ์ธ / Check for errors
1)js = Jump if Carry
2)BIOS ๋์คํฌ ์ฝ๊ธฐ ์ธํฐ๋ฝํธ(int 0x13)๋ ์์
์ ๋ง์น ํ ์ฑ๊ณต ์ฌ๋ถ๋ฅผ CPU์ Carry Flag(CF)๋ผ๋ ์ ํธ๋ฑ์ ํ์ํด ์ฃผ๋๋ก ์ฝ์๋์ด ์์ต๋๋ค.
The BIOS disk read interrupt (int 0x13) is designed to indicate the success or failure of an operation after completion using a signal known as the CPU’s Carry Flag (CF).
3)Carry Flag = 0์ ๋์คํฌ ์ฝ๊ธฐ ์ฑ๊ณต์ด๊ณ Carry Flag = 1์ ๋์คํฌ ์ฝ๊ธฐ ์คํจ์
๋๋ค.
Carry Flag = 0 indicates a successful disk read, while Carry Flag = 1 indicates a failed disk read.
4)Carry Flag(์บ๋ฆฌ ํ๋๊ทธ)๊ฐ 1๋ก ์ธํ
๋์ด ์๋ค๋ฉด disk_error ๋ผ๋ฒจ๋ก ์ ํํฉ๋๋ค.
If the Carry Flag is set to 1, the program jumps to the disk_error label.
jc disk_error
— ๋ก๋๋ 2๋ฒ ์นํฐ(sector2.asm)๋ก ์ ํํฉ๋๋ค.
Jump to the loaded sector 2 (sector2.asm).
jmp 0x8000
— ์ค๋ฅ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
Outputs an error.
disk_error:
mov si, msg_error
call print_string
jmp hang
1) ์ถ๋ ฅํ ์๋ฌ๋ฉ์ธ์ง๋ฅผ ์ง์ ํฉ๋๋ค.
Specifies the error message to be output.
mov si, msg_error
2) ์๋ฌ๋ฉ์ธ์ง๋ฅผ ํ๋ฉด์ ์ถ๋ ฅํฉ๋๋ค.
Displays the error message on the screen.
call print_string
3) ๋๊ธฐ๋ชจ๋ ์ง์
(hang๋ผ๋ฒจ๋ก ์ ํ)
Enter standby mode (jump to ‘hang’ label)
jmp hang
— ๋๊ธฐ๋ชจ๋์
๋๋ค.(์๊ธฐ ์์ ์ ์์น๋ก ์ ํํฉ๋๋ค.)
Standby mode. (Jumps to its own position.)
hang:
jmp $
— ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅ๋ ๋ฌธ์์ด์ ํ ๊ธ์์ฉ ์ฝ์ด์, ํ๋ฉด์ ์ฐ์์ผ๋ก ์ถ๋ ฅํ๋ ํจ์์
๋๋ค.
This function reads a string stored in memory character by character and outputs it to the screen continuously.
1)SI ๋ ์ง์คํฐ๊ฐ ๊ฐ๋ฆฌํค๋ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์์์ ๋ฑ 1๋ฐ์ดํธ(๋ฌธ์ 1๊ธ์)๋ฅผ ์ฝ์ด์ AL ๋ ์ง์คํฐ์ ์ ์ฅํฉ๋๋ค.
It reads exactly one byte (a single character) from the memory address pointed to by the SI register and stores it in the AL register.
1-1)๋์์, ๋ค์ ๊ธ์๋ฅผ ์ฝ์ ์ ์๋๋ก SI ๋ ์ง์คํฐ์ ์ฃผ์ ๊ฐ์ ์๋์ผ๋ก 1 ์ฆ๊ฐ์ํต๋๋ค.
At the same time, the address value of the SI register is automatically incremented by 1 to allow the next character to be read.
1-2)์ด ๋ช
๋ น์ด ํ ์ค๋ก “๊ธ์ ์ฝ๊ธฐ + ๋ค์ ๊ธ์๋ก ํ์ดํ ์ด๋”์ด ๋์์ ์ผ์ด๋ฉ๋๋ค.
With this single command, “reading the character” and “moving the arrow to the next character” happen simultaneously.
lodsb
2)๋ฌธ์์ด์ ๋์ธ์ง ํ์ธํฉ๋๋ค.(๋ฌธ์์ด ๋์ 0์ด ์๋์ง ํ์ธ)
Checks if it is the end of the string (checks for a null terminator at the end of the string).
cmp al, 0
3)๋๋ฌ์ผ๋ฉด ํจ์ ์ข
๋ฃ ์์น(.done)๋ก ํฉ๋๋ค.
If finished, proceed to the function termination point (.done).
4) je (Jump if Equal) , AL์ด 0์ด๋ผ๋ฉด .done ๋ผ๋ฒจ ์์น๋ก ์ ํํ๋ผ๋ ๋ป์
๋๋ค.je (Jump if Equal) means to jump to the .done label if AL is 0.
je .done
— ํ
๋ ํ์ดํ ํ์์ผ๋ก ํ๋ฉด ์ถ๋ ฅ์ ์ค์ ํฉ๋๋ค.(ํ ๊ธ์์ฉ ์ถ๋ ฅ)
Configures the screen output to teletype format (printing one character at a time).
mov ah, 0x0e
— BIOS ๋น๋์ค ์ธํฐ๋ฝํธ๋ฅผ ์คํํฉ๋๋ค. CPU๋ AL ๋ ์ง์คํฐ์ ๋ค์ด์๋ ๋ฌธ์๋ฅผ ํ๋ฉด ์ปค์ ์์น์ ๋ฐ๋ก ์ฐ์ด์ค๋๋ค.
It executes the BIOS video interrupt. The CPU directly displays the character contained in the AL register at the screen cursor’s position.
int 0x10
— ํจ์ ์ข
๋ฃ ๋ฐ ๋ณต๊ท
Function Termination and Return
.done:
ret
1)je ๋ช
๋ น์ด๊ฐ ํ์ถํ๋ ๋ชฉ์ ์ง ๋ผ๋ฒจ์
๋๋ค. (์ด๋ฆ ์์ ๋ง์นจํ.๊ฐ ๋ถ์ ๊ฒ์ print_string ํจ์ ๋ด๋ถ์์๋ง ์ฐ๋ ๋ก์ปฌ ๋ผ๋ฒจ์ด๋ผ๋ ๋ป์
๋๋ค.)
This is the destination label that the je instruction jumps to. (A period at the beginning of the name indicates a local label used only within the print_string function.)
.done
2)ret (Return): ์ด ํจ์๋ฅผ ํธ์ถํ๋ ์๋ ์๋ฆฌ(call print_string ๋ฐ๋ก ๋ค์ ์ค)๋ก CPU ์คํ ์์น๋ฅผ ๋๋ ค๋ณด๋ด๋ ๋ช
๋ น์
๋๋ค.
ret (Return): An instruction that returns the CPU’s execution point to the original location where the function was called (the line immediately following call print_string).
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_boot db '1. Booting MBR...', 13, 10, 0
msg_success db '2. Disk read success!', 13, 10, 0
msg_error db 'Disk read failed!', 13, 10, 0
— ๊ณ์ฐ๋ ํ์๋งํผ ๋ฐ์ดํธ(db) ๊ณต๊ฐ์ ์ ๋ถ 0์ผ๋ก ์ฑ์ฐ๋ผ๋ ๋ช
๋ น์ด์
๋๋ค.
This command fills the specified number of bytes (db) with zeros.
1) 512๋ฐ์ดํธ์์ 510๋ฐ์ดํธ๋ ๋ถํธ๋ก๋ ๋ฐ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ ๊ณต๊ฐ์
๋๋ค.
Of the 512 bytes, 510 bytes are used to store the bootloader and data.
2) ๋๋จธ์ง ๋ง์ง๋ง 2๋ฐ์ดํธ๋ ๋ถํ
๊ฐ๋ฅ ์ฌ๋ถ๋ฅผ ํ๋ณํ๊ธฐ ์ํ ์๊ทธ๋์ฒ๋ก ์ฌ์ฉ๋๋ฉฐ ๋ณดํต 16์ง์ 0xAA55๊ฐ ๋ค์ด๊ฐ๋๋ค.
The final two bytes serve as a signature to determine bootability and typically contain the hexadecimal value 0xAA55.
times 510 - ($ - $$) db 0
— ๋ถํ ํ์ธ์ฝ๋ ๊ธฐ๋ก / Record Boot Verification Code
1) dw๋ “define word”์ ์ฝ์๋ก, 2๋ฐ์ดํธ(16๋นํธ) ๋ฐ์ดํฐ๋ฅผ ์ ์ธํ๊ฑฐ๋ ์ ์ฅํ ๋ ์ฌ์ฉํฉ๋๋ค.dw stands for “define word” and is used to declare or store 2-byte (16-bit) data.
2) ๋ถํธ ์นํฐ์ 0xaa55๊ฐ์ ๋ง์ง๋ง์ ๊ธฐ๋กํฉ๋๋ค.
Write the value 0xaa55 to the end of the boot sector.
3) ์ด ๊ฐ์ด ์์ด์ผ BIOS๊ฐ ํด๋น ์นํฐ๋ฅผ ๋ถํ
๊ฐ๋ฅํ ๊ฒ์ผ๋ก ์ธ์ํฉ๋๋ค.
The BIOS requires this value to recognize the sector as bootable.
dw 0xaa55