{"id":6060,"date":"2026-06-24T18:52:08","date_gmt":"2026-06-24T09:52:08","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=6060"},"modified":"2026-06-24T19:07:37","modified_gmt":"2026-06-24T10:07:37","slug":"os-minios-3-1","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/06\/24\/os-minios-3-1\/","title":{"rendered":"[OS]miniOS-3(1)"},"content":{"rendered":"\n<p>\ub514\uc2a4\ud06c\uc5d0\uc11c \ucd94\uac00 \ub370\uc774\ud130 \ub85c\ub4dc\ud558\ub294 \ubc29\ubc95\uc5d0 \ub300\ud55c \uc124\uba85\uc785\ub2c8\ub2e4.<br>This explains how to load additional data from the disk.<\/p>\n\n\n\n<p>\ud83d\udc49\ufe0f \ub514\uc2a4\ud06c\ub294 \ud50c\ub85c\ud53c \ub514\uc2a4\ud06c\uc785\ub2c8\ub2e4.<br>The disk is a floppy disk.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83d\udc49\ufe0f \uc804\uccb4\ucf54\ub4dc(NASM) \/ Full Code(NASM)<\/p>\n\n\n\n<p>\u2714\ufe0f boot.asm<\/p>\n\n\n\n<p>&#8212; \uccab \ubc88\uc9f8 \uc139\ud130(512\ubc14\uc774\ud2b8)\ub9cc \ub2f4\ub2f9\ud558\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4.<br>This code handles only the first sector (512 bytes).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;org 0x7c00]\nbits 16\n\nstart:\n    mov ax, 0\n    mov ds, ax\n    mov es, ax\n\n    mov si, msg_boot\n    call print_string\n\n    ; \ub514\uc2a4\ud06c \uc77d\uae30 (2\ubc88 \uc139\ud130\ubd80\ud130 1\uac1c \uc139\ud130\ub97c 0x8000\uc5d0 \ub85c\ub4dc)\n    ; Disk read (load 1 sector starting from sector 2 to 0x8000)\n    mov ah, 0x02\n    mov al, 1\n    mov ch, 0\n    mov cl, 2\n    mov dh, 0\n    mov bx, 0x8000\n    int 0x13\n\n    jc disk_error\n\n    mov si, msg_success\n    call print_string\n\n    ; \ub85c\ub4dc\ub41c 2\ubc88 \uc139\ud130 \ucf54\ub4dc\ub85c \uc810\ud504\n    ; Jump to loaded sector 2 code\n    jmp 0x8000\n\ndisk_error:\n    mov si, msg_error\n    call print_string\n    jmp hang\n\nhang:\n    jmp $\n\nprint_string:\n    lodsb\n    cmp al, 0\n    je .done\n    mov ah, 0x0e\n    int 0x10\n    jmp print_string\n.done:\n    ret\n\nmsg_boot    db '1. Booting MBR...', 13, 10, 0\nmsg_success db '2. Disk read success!', 13, 10, 0\nmsg_error   db 'Disk read failed!', 13, 10, 0\n\ntimes 510 - ($ - $$) db 0\ndw 0xaa55\n<\/code><\/pre>\n\n\n\n<p>&#8212; \uba54\ubaa8\ub9ac 0x8000\uc5d0 \ub85c\ub4dc\ub418\uc5b4 \uc2e4\ud589\ub420 \ub3c5\ub9bd\ub41c \ucf54\ub4dc \ud30c\uc77c\uc785\ub2c8\ub2e4. \ub611\uac19\uc774 512\ubc14\uc774\ud2b8 \ud06c\uae30\ub97c \ub9de\ucdb0\uc90d\ub2c8\ub2e4.<br>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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;org 0x8000]\nbits 16\n\nstart:\n    mov si, msg_next_sector\n    call print_string\n    \n    ; \ub300\uae30\ubaa8\ub4dc \/ Standby mode\n    jmp $\n\nprint_string:\n    lodsb\n    cmp al, 0\n    je .done\n    mov ah, 0x0e\n    int 0x10\n    jmp print_string\n.done:\n    ret\n\nmsg_next_sector db '3. Hello from Sector 2 (0x8000)!', 13, 10, 0\n\ntimes 512 - ($ - $$) db 0\n<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ufe0f\ucef4\ud30c\uc77c \ubc0f \uc2e4\ud589 \ubc29\ubc95 (QEMU \uae30\uc900)<br>How to compile and run (using QEMU)<\/p>\n\n\n\n<p>\u2714\ufe0f Xubuntu \ud130\ubbf8\ub110\uc5d0\uc11c \ub2e4\uc74c \uba85\ub839\uc5b4\ub97c \uc21c\uc11c\ub300\ub85c \uc2e4\ud589\ud569\ub2c8\ub2e4.<br>Run the following commands in order in the Xubuntu terminal.<\/p>\n\n\n\n<p>\u2714\ufe0f \ub450 \ucf54\ub4dc\ub97c \uac01\uac01 \ube4c\ub4dc\ud55c \ub4a4 \ub9ac\ub205\uc2a4\uc758 <code>cat<\/code>\uacfc <code>dd<\/code> \uba85\ub839\uc5b4\ub85c \uc644\ubcbd\ud55c \uac00\uc0c1 \ub514\uc2a4\ud06c \uc774\ubbf8\uc9c0\ub97c \ub9cc\ub4ed\ub2c8\ub2e4.<br>After building each piece of code, create a complete virtual disk image using the Linux <code>cat<\/code> and <code>dd<\/code> commands.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. \uac01\uac01\uc758 \uc5b4\uc148\ube14\ub9ac \ud30c\uc77c\uc744 \ubc14\uc774\ub108\ub9ac\ub85c \ucef4\ud30c\uc77c\n# Compile each assembly file into binary\n\nnasm -f bin boot.asm -o boot.bin\nnasm -f bin sector2.asm -o sector2.bin\n\n# 2. \ub450 \ud30c\uc77c\uc744 \ud558\ub098\ub85c \ud569\uce68 (\ucd1d 1024\ubc14\uc774\ud2b8)\n# Merged two files into one (total 1,024 bytes)\n\ncat boot.bin sector2.bin &gt; temp.bin\n\n# 3. \uac00\uc0c1 \uba38\uc2e0 BIOS\uac00 \uc624\uc778\ud558\uc9c0 \uc54a\ub3c4\ub85d 1.44MB \ud50c\ub85c\ud53c \ub514\uc2a4\ud06c \uaddc\uaca9\uc73c\ub85c \ube48 \uacf5\uac04 \ucc44\uc6b0\uae30\n# Pad the empty space to the 1.44MB floppy disk specification \n# to prevent the virtual machine BIOS from misinterpreting it.\n\ndd if=temp.bin of=os.img bs=512 count=2880 conv=sync\n\n# 4. QEMU \uc2e4\ud589\n# Run QEMU\n\nqemu-system-x86_64 -drive file=os.img,format=raw,if=floppy -boot a\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83d\udc49\ufe0f\ucf54\ub4dc \uc124\uba85 \/ Code Explanation<\/p>\n\n\n\n<p>\u2714\ufe0f boot.asm<\/p>\n\n\n\n<p>&#8212; \ub808\uc9c0\uc2a4\ud130\ub97c 0\uc73c\ub85c \ucd08\uae30\ud654 \ud569\ub2c8\ub2e4.<br>Initialize the register to zero.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    mov ax, 0\n    mov ds, ax\n    mov es, ax<\/code><\/pre>\n\n\n\n<p>1) \uc138\uadf8\uba3c\ud2b8 \ub808\uc9c0\uc2a4\ud130\ub294 \uc9c1\uc811 \uac12\uc744 \ub300\uc785\ud560 \uc218 \uc5c6\uc2b5\ub2c8\ub2e4.<br>You cannot directly assign values \u200b\u200bto segment registers.<\/p>\n\n\n\n<p>2) \uadf8\ub798\uc11c \ubc94\uc6a9\ub808\uc9c0\uc2a4\ud130\uc5d0 0\uc744 \ub300\uc785\ud558\uace0 \uc774 \ubc94\uc6a9 \ub808\uc9c0\uc2a4\ud130\ub97c \uc138\uadf8\uba3c\ud2b8\ub808\uc9c0\uc2a4\ud130\uc5d0 \ub2e4\uc2dc \ub300\uc785\ud569\ub2c8\ub2e4.<br>So, we assign 0 to a general-purpose register and then assign that register to a segment register.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\ud83d\udcd316\ube44\ud2b8 \ucef4\ud4e8\ud130 \uc138\uadf8\uba3c\ud2b8\ub808\uc9c0\uc2a4\ud130 \/ 16-bit computer segment register\n\nds (Data Segment): \n\ucf54\ub4dc\uc5d0\uc11c \uc0ac\uc6a9\ud560 \ubb38\uc790\uc5f4, \ubcc0\uc218 \ub4f1\uc758 \ub370\uc774\ud130 \uc8fc\uc18c \uae30\uc900\uc810\uc744 \uac00\ub9ac\ud0b5\ub2c8\ub2e4.\nIt points to the reference point for data addresses\u2014such as strings and variables\u2014used in the code.\n\nes (Extra Segment): \n\ub514\uc2a4\ud06c\uc5d0\uc11c \ub370\uc774\ud130\ub97c \uc77d\uc5b4\uc624\uac70\ub098 \uba54\ubaa8\ub9ac\ub97c \ubcf5\uc0ac\ud560 \ub54c \uc4f0\ub294 \ucd94\uac00 \ubaa9\uc801\uc9c0 \uc8fc\uc18c \uae30\uc900\uc810\uc785\ub2c8\ub2e4.\nThis is an additional destination address reference point used when reading data from a disk or copying memory.\n\ncs (Code Segment): \nCPU\uac00 \uc9c0\uae08 \uc2e4\ud589\ud558\uace0 \uc788\ub294 \uae30\uacc4\uc5b4 \ucf54\ub4dc\uc758 \uc8fc\uc18c \uae30\uc900\uc810\uc785\ub2c8\ub2e4.\nIt is the reference address for the machine code currently being executed by the CPU.\n\nss (Stack Segment): \n\ud568\uc218 \ud638\ucd9c\uc774\ub098 \uc784\uc2dc \ub370\uc774\ud130 \uc800\uc7a5\uc5d0 \uc4f0\ub294 \uc2a4\ud0dd \uba54\ubaa8\ub9ac\uc758 \uc8fc\uc18c \uae30\uc900\uc810\uc785\ub2c8\ub2e4\nIt is the reference address for the stack memory used for function calls or temporary data storage.<\/code><\/pre>\n\n\n\n<p>&#8212; mov si, msg_boot \uc5ec\uae30 si\ub808\uc9c0\uc2a4\ud130\uc5d0 msg_boot\uc5d0 \uc800\uc7a5\ub41c \uac12\uc758 \uc8fc\uc18c\ub97c \uc800\uc7a5\ud569\ub2c8\ub2e4.<br><code>mov si, msg_boot<\/code> stores the address of the value held in <code>msg_boot<\/code> into the <code>si<\/code> register.<\/p>\n\n\n\n<p>1)msg_boot\ubcc0\uc218\uc5d0\ub294 msg_boot db &#8216;1. Booting MBR\u2026&#8217;, 13, 10, 0 \uc774\ub807\uac8c \uc800\uc7a5\ub418\uc5b4 \uc788\uc2b5\ub2c8\ub2e4.<br>The <code>msg_boot<\/code> variable stores the following: <code>msg_boot db '1. Booting MBR\u2026', 13, 10, 0<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  mov si, msg_boot<\/code><\/pre>\n\n\n\n<p>&#8212; \ud568\uc218\ub97c \uc2e4\ud589\ud569\ub2c8\ub2e4.<br>Executes the function.<\/p>\n\n\n\n<p>1)\ud30c\uc77c \uc544\ub798\uc5d0  print_string: \ub77c\ubca8\uc774\uc788\uc2b5\ub2c8\ub2e4.<br>There is a <code>print_string:<\/code> label at the bottom of the file.<\/p>\n\n\n\n<p>2) call print_string\ud558\uba74 \ub3cc\uc544\uc62c \uc8fc\uc18c\ub97c \uc2a4\ud0dd\uc5d0 \uc800\uc7a5\ud558\uace0 \uc810\ud504\ud569\ub2c8\ub2e4.<br>Calling <code>print_string<\/code> saves the return address onto the stack and then jumps.<\/p>\n\n\n\n<p>3) \ud615\ud0dc\ub294 \ub77c\ubca8\uc774\uc9c0\ub9cc \uc774\uac83\uc744 \uae30\ub2a5\uc801\uc73c\ub85c \ud568\uc218\ub77c\uace0 \ud569\ub2c8\ub2e4.<br>Although it takes the form of a label, functionally it is referred to as a function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>call print_string<\/code><\/pre>\n\n\n\n<p>&#8212; \ub514\uc2a4\ud06c \uc77d\uae30 \/ Disk read<\/p>\n\n\n\n<p>1)<strong>\ub514\uc2a4\ud06c \uc139\ud130\ub97c \uba54\ubaa8\ub9ac\ub85c \uc77d\uc5b4\uc624\uaca0\ub2e4(Read Sectors)&#8221;<\/strong>\ub294 \uae30\ub2a5 \ubc88\ud638(<code>0x02<\/code>)\ub97c \uc120\ud0dd\ud558\ub294 \uba85\ub839\uc785\ub2c8\ub2e4.<br>This is a command to select function number 0x02, which reads disk sectors into memory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mov ah, 0x02<\/code><\/pre>\n\n\n\n<p>2)\ub514\uc2a4\ud06c\uc5d0\uc11c <strong>\uba87 \uac1c\uc758 \uc139\ud130<\/strong>\ub97c \uc77d\uc744\uc9c0 \uc9c0\uc815\ud569\ub2c8\ub2e4. \uc5ec\uae30\uc11c\ub294 <code>1<\/code> \uc139\ud130(512\ubc14\uc774\ud2b8)\ub9cc\ud07c \uc77d\uaca0\ub2e4\ub294 \ub73b\uc785\ub2c8\ub2e4.<br>Specifies how many sectors to read from the disk. In this case, it means reading one sector (512 bytes).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mov al, 1<\/code><\/pre>\n\n\n\n<p>3) (\uc2e4\ub9b0\ub354 \ubc88\ud638)\ub514\uc2a4\ud06c \ud2b8\ub799\uc758 \uc704\uce58\ub97c \ub098\ud0c0\ub0b4\ub294 <strong>\uc2e4\ub9b0\ub354(Cylinder) \ubc88\ud638\ub97c 0\ubc88<\/strong>\uc73c\ub85c \uc9c0\uc815\ud569\ub2c8\ub2e4. \ub514\uc2a4\ud06c\uc758 \ub9e8 \ubc14\uae65\ucabd \uac00\uc7a5\uc790\ub9ac\ub97c \ub73b\ud569\ub2c8\ub2e4.<br>(Cylinder Number) Specifies the cylinder number\u2014representing the position of the disk track\u2014as 0. This refers to the outermost edge of the disk.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mov ch, 0 <\/code><\/pre>\n\n\n\n<p>4)(\uc139\ud130 \ubc88\ud638)\ub514\uc2a4\ud06c\uc758 \uba87 \ubc88\uc9f8 \uc139\ud130\ubd80\ud130 \uc77d\uae30 \uc2dc\uc791\ud560\uc9c0 \uc9c0\uc815\ud569\ub2c8\ub2e4. \ubd80\ud2b8 \ub85c\ub354(MBR)\uac00 1\ubc88 \uc139\ud130\uc5d0 \ub4e4\uc5b4\uc788\uc73c\ubbc0\ub85c, \uadf8 \ubc14\ub85c \ub2e4\uc74c \uc601\uc5ed\uc778 2\ubc88 \uc139\ud130\ub97c \uc9c0\uc815\ud55c \uac83\uc785\ub2c8\ub2e4.<br>(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\u2014the area immediately following it\u2014has been specified.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mov cl, 2<\/code><\/pre>\n\n\n\n<p>5)(\ud5e4\ub4dc \ubc88\ud638)\ub514\uc2a4\ud06c\uc758 \uc55e\ub4b7\uba74\uc744 \uacb0\uc815\ud558\ub294 <strong>\ud5e4\ub4dc(Head) \ubc88\ud638\ub97c 0\ubc88<\/strong>\uc73c\ub85c \uc9c0\uc815\ud569\ub2c8\ub2e4. (\ub2e8\uba74 \ub610\ub294 \uccab \ubc88\uc9f8 \uba74\uc744 \ub73b\ud568)<br>(Head Number) Specifies the head number\u2014which determines the front or back side of the disk\u2014as 0 (indicating the single side or the first side).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mov dh, 0<\/code><\/pre>\n\n\n\n<p>6)(\uc800\uc7a5\ud560 \uba54\ubaa8\ub9ac \uc8fc\uc18c)\ub514\uc2a4\ud06c\uc5d0\uc11c \uc77d\uc5b4\uc628 512\ubc14\uc774\ud2b8 \ub370\uc774\ud130\ub97c <strong>\uba54\ubaa8\ub9ac\uc758 \uba87 \ubc88\uc9c0 \uc790\ub9ac\uc5d0 \uc800\uc7a5\ud560\uc9c0<\/strong> \uc9c0\uc815\ud558\ub294 \ubaa9\uc801\uc9c0 \uc8fc\uc18c\uc785\ub2c8\ub2e4. <br>(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.<\/p>\n\n\n\n<p>\uc55e\uc11c \ub370\uc774\ud130 \uc138\uadf8\uba3c\ud2b8(<code>ES<\/code>)\ub97c <code>0<\/code>\uc73c\ub85c \ucd08\uae30\ud654\ud588\uc73c\ubbc0\ub85c, \uc2e4\uc81c \uc800\uc7a5 \uc704\uce58\ub294 <code>0x0000:0x8000<\/code>\uc774 \ub429\ub2c8\ub2e4.<br>Since the data segment (ES) was previously initialized to 0, the actual storage location becomes 0x0000:0x8000.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mov bx, 0x8000<\/code><\/pre>\n\n\n\n<p>7)(\uc778\ud130\ub7fd\ud2b8 \uc2e4\ud589)\uc704\uc5d0\uc11c \uc124\uc815\ud55c \ubaa8\ub4e0 \ub808\uc9c0\uc2a4\ud130 \uc815\ubcf4\ub97c \uac00\uc9c0\uace0 <strong>BIOS \ub514\uc2a4\ud06c \uc778\ud130\ub7fd\ud2b8\ub97c \ucd5c\uc885 \ud638\ucd9c(\uc2e4\ud589)<\/strong>\ud569\ub2c8\ub2e4. <br>(Interrupt Execution) The BIOS disk interrupt is finally called (executed) using all the register information configured above.<\/p>\n\n\n\n<p>\ub514\uc2a4\ud06c \ud558\ub4dc\uc6e8\uc5b4\uac00 \uc774 \uc2e0\ud638\ub97c \ubc1b\uc544 \uc9c0\uc815\ub41c \ub370\uc774\ud130\ub97c \uba54\ubaa8\ub9ac\uc5d0 \ubcf5\uc0ac\ud574 \ub123\uc2b5\ub2c8\ub2e4.<br>The disk hardware receives this signal and copies the specified data into memory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int 0x13<\/code><\/pre>\n\n\n\n<p>\u2705 \ubd80\ud2b8\ub85c\ub354\uac00 1\ubc88\uc778\uac83\uc744 \uc5b4\ub5bb\uac8c \uc54c \uc218 \uc788\ub098?<br>How can I tell that the bootloader is number 1?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\ucef4\ud4e8\ud130 \ud558\ub4dc\uc6e8\uc5b4(CPU\uc640 BIOS)\ub97c \ub9cc\ub4e0 \uc81c\uc870\uc0ac\ub4e4\uc774 \uc804 \uc138\uacc4\uc801\uc778 \uaddc\uce59(\ud45c\uc900 \ub514\ubc14\uc774\uc2a4 \uaddc\uaca9)\uc73c\ub85c \uadf8\ub807\uac8c \uc815\ud574\ub193\uc558\uae30 \ub54c\ubb38\uc785\ub2c8\ub2e4.\nThis is because the manufacturers of computer hardware (CPU and BIOS) established it that way as a global rule (standard device specification).\n\n\ud558\ub4dc\ub514\uc2a4\ud06c, \ud50c\ub85c\ud53c\ub514\uc2a4\ud06c, USB \ub4f1 \ubaa8\ub4e0 \ubd80\ud305 \ub9e4\uccb4\uc758 \ub9e8 \uccab \ubc88\uc9f8 \uce78(1\ubc88 \uc139\ud130, 512\ubc14\uc774\ud2b8)\uc744 MBR(\ub9c8\uc2a4\ud130 \ubd80\ud2b8 \ub808\ucf54\ub4dc) \ub610\ub294 \ubd80\ud2b8 \uc139\ud130\ub77c\uace0 \ubd80\ub985\ub2c8\ub2e4.\nThe very first segment (Sector 1, 512 bytes) of any boot medium\u2014such as a hard disk, floppy disk, or USB drive\u2014is called the MBR (Master Boot Record) or boot sector.\n\n\uc2dc\uc2a4\ud15c\uc774 \ucf1c\uc9c8 \ub54c \uba54\uc778\ubcf4\ub4dc\uc758 BIOS\uac00 \ubb34\uc870\uac74 \ub514\uc2a4\ud06c\uc758 \uccab \ubc88\uc9f8 \uc139\ud130(\uc2e4\ub9b0\ub354 0, \ud5e4\ub4dc 0, \uc139\ud130 1)\ub97c \uac00\uc7a5 \uba3c\uc800 \uc77d\ub3c4\ub85d \uc124\uacc4\ub418\uc5b4 \uc788\uae30 \ub54c\ubb38\uc785\ub2c8\ub2e4.(\ub514\uc2a4\ud06c \uc139\ud130 \ubc88\ud638\ub294 1\ubd80\ud130 \uc2dc\uc791)\nThis 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).<\/code><\/pre>\n\n\n\n<p>&#8212; \uc624\ub958 \ud655\uc778 \/ Check for errors<\/p>\n\n\n\n<p>1)js = Jump if Carry<\/p>\n\n\n\n<p>2)BIOS \ub514\uc2a4\ud06c \uc77d\uae30 \uc778\ud130\ub7fd\ud2b8(int 0x13)\ub294 \uc791\uc5c5\uc744 \ub9c8\uce5c \ud6c4 \uc131\uacf5 \uc5ec\ubd80\ub97c CPU\uc758 Carry Flag(CF)\ub77c\ub294 \uc2e0\ud638\ub4f1\uc5d0 \ud45c\uc2dc\ud574 \uc8fc\ub3c4\ub85d \uc57d\uc18d\ub418\uc5b4 \uc788\uc2b5\ub2c8\ub2e4.<br>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&#8217;s Carry Flag (CF).<\/p>\n\n\n\n<p>3)Carry Flag = <strong><code>0<\/code><\/strong>\uc740 \ub514\uc2a4\ud06c \uc77d\uae30 \uc131\uacf5\uc774\uace0 Carry Flag = <strong><code>1<\/code><\/strong>\uc740 \ub514\uc2a4\ud06c \uc77d\uae30 \uc2e4\ud328\uc785\ub2c8\ub2e4.<br>Carry Flag = 0 indicates a successful disk read, while Carry Flag = 1 indicates a failed disk read.<\/p>\n\n\n\n<p>4)Carry Flag(\uce90\ub9ac \ud50c\ub798\uadf8)\uac00 1\ub85c \uc138\ud305\ub418\uc5b4 \uc788\ub2e4\uba74 disk_error \ub77c\ubca8\ub85c \uc810\ud504\ud569\ub2c8\ub2e4.<br>If the Carry Flag is set to 1, the program jumps to the <code>disk_error<\/code> label.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> jc disk_error<\/code><\/pre>\n\n\n\n<p>&#8212; \ub85c\ub4dc\ub41c 2\ubc88 \uc139\ud130(sector2.asm)\ub85c \uc810\ud504\ud569\ub2c8\ub2e4.<br>Jump to the loaded sector 2 (sector2.asm).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>jmp 0x8000<\/code><\/pre>\n\n\n\n<p>&#8212; \uc624\ub958\ub97c \ucd9c\ub825\ud569\ub2c8\ub2e4.<br>Outputs an error.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>disk_error:\n    mov si, msg_error\n    call print_string\n    jmp hang<\/code><\/pre>\n\n\n\n<p>1) \ucd9c\ub825\ud560 \uc5d0\ub7ec\uba54\uc138\uc9c0\ub97c \uc9c0\uc815\ud569\ub2c8\ub2e4.<br>Specifies the error message to be output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mov si, msg_error<\/code><\/pre>\n\n\n\n<p>2) \uc5d0\ub7ec\uba54\uc138\uc9c0\ub97c \ud654\uba74\uc5d0 \ucd9c\ub825\ud569\ub2c8\ub2e4.<br>Displays the error message on the screen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>call print_string<\/code><\/pre>\n\n\n\n<p>3) \ub300\uae30\ubaa8\ub4dc \uc9c4\uc785(hang\ub77c\ubca8\ub85c \uc810\ud504)<br>Enter standby mode (jump to &#8216;hang&#8217; label)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>jmp hang<\/code><\/pre>\n\n\n\n<p>&#8212; \ub300\uae30\ubaa8\ub4dc\uc785\ub2c8\ub2e4.(\uc790\uae30 \uc790\uc2e0\uc758 \uc704\uce58\ub85c \uc810\ud504\ud569\ub2c8\ub2e4.)<br>Standby mode. (Jumps to its own position.)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hang:\n    jmp $<\/code><\/pre>\n\n\n\n<p>&#8212; \uba54\ubaa8\ub9ac\uc5d0 \uc800\uc7a5\ub41c \ubb38\uc790\uc5f4\uc744 \ud55c \uae00\uc790\uc529 \uc77d\uc5b4\uc11c, \ud654\uba74\uc5d0 \uc5f0\uc18d\uc73c\ub85c \ucd9c\ub825\ud558\ub294 \ud568\uc218\uc785\ub2c8\ub2e4.<br>This function reads a string stored in memory character by character and outputs it to the screen continuously.<\/p>\n\n\n\n<p>1)SI \ub808\uc9c0\uc2a4\ud130\uac00 \uac00\ub9ac\ud0a4\ub294 \uba54\ubaa8\ub9ac \uc8fc\uc18c\uc5d0\uc11c \ub531 1\ubc14\uc774\ud2b8(\ubb38\uc790 1\uae00\uc790)\ub97c \uc77d\uc5b4\uc640 AL \ub808\uc9c0\uc2a4\ud130\uc5d0 \uc800\uc7a5\ud569\ub2c8\ub2e4.<br>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.<\/p>\n\n\n\n<p>1-1)\ub3d9\uc2dc\uc5d0, \ub2e4\uc74c \uae00\uc790\ub97c \uc77d\uc744 \uc218 \uc788\ub3c4\ub85d SI \ub808\uc9c0\uc2a4\ud130\uc758 \uc8fc\uc18c \uac12\uc744 \uc790\ub3d9\uc73c\ub85c 1 \uc99d\uac00\uc2dc\ud0b5\ub2c8\ub2e4.<br>At the same time, the address value of the SI register is automatically incremented by 1 to allow the next character to be read.<\/p>\n\n\n\n<p>1-2)\uc774 \uba85\ub839\uc5b4 \ud55c \uc904\ub85c &#8220;\uae00\uc790 \uc77d\uae30 + \ub2e4\uc74c \uae00\uc790\ub85c \ud654\uc0b4\ud45c \uc774\ub3d9&#8221;\uc774 \ub3d9\uc2dc\uc5d0 \uc77c\uc5b4\ub0a9\ub2c8\ub2e4.<br>With this single command, &#8220;reading the character&#8221; and &#8220;moving the arrow to the next character&#8221; happen simultaneously.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>lodsb<\/code><\/pre>\n\n\n\n<p>2)\ubb38\uc790\uc5f4\uc758 \ub05d\uc778\uc9c0 \ud655\uc778\ud569\ub2c8\ub2e4.(\ubb38\uc790\uc5f4 \ub05d\uc5d0 0\uc774 \uc788\ub294\uc9c0 \ud655\uc778)<br>Checks if it is the end of the string (checks for a null terminator at the end of the string).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cmp al, 0<\/code><\/pre>\n\n\n\n<p>3)\ub05d\ub0ac\uc73c\uba74 \ud568\uc218 \uc885\ub8cc \uc704\uce58(.done)\ub85c \ud569\ub2c8\ub2e4.<br>If finished, proceed to the function termination point (.done).<\/p>\n\n\n\n<p>4) je (Jump if Equal) , AL\uc774 0\uc774\ub77c\uba74 .done \ub77c\ubca8 \uc704\uce58\ub85c \uc810\ud504\ud558\ub77c\ub294 \ub73b\uc785\ub2c8\ub2e4.<br><code>je<\/code> (Jump if Equal) means to jump to the <code>.done<\/code> label if AL is 0.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>je .done<\/code><\/pre>\n\n\n\n<p>&#8212; \ud154\ub808\ud0c0\uc774\ud504 \ud615\uc2dd\uc73c\ub85c \ud654\uba74 \ucd9c\ub825\uc744 \uc124\uc815\ud569\ub2c8\ub2e4.(\ud55c \uae00\uc790\uc529 \ucd9c\ub825)<br>Configures the screen output to teletype format (printing one character at a time).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mov ah, 0x0e<\/code><\/pre>\n\n\n\n<p>&#8212; BIOS \ube44\ub514\uc624 \uc778\ud130\ub7fd\ud2b8\ub97c \uc2e4\ud589\ud569\ub2c8\ub2e4. CPU\ub294 AL \ub808\uc9c0\uc2a4\ud130\uc5d0 \ub4e4\uc5b4\uc788\ub294 \ubb38\uc790\ub97c \ud654\uba74 \ucee4\uc11c \uc704\uce58\uc5d0 \ubc14\ub85c \ucc0d\uc5b4\uc90d\ub2c8\ub2e4.<br>It executes the BIOS video interrupt. The CPU directly displays the character contained in the AL register at the screen cursor&#8217;s position.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int 0x10<\/code><\/pre>\n\n\n\n<p>&#8212; \ud568\uc218 \uc885\ub8cc \ubc0f \ubcf5\uadc0<br>Function Termination and Return<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.done:\n    ret<\/code><\/pre>\n\n\n\n<p>1)je \uba85\ub839\uc5b4\uac00 \ud0c8\ucd9c\ud558\ub294 \ubaa9\uc801\uc9c0 \ub77c\ubca8\uc785\ub2c8\ub2e4. (\uc774\ub984 \uc55e\uc5d0 \ub9c8\uce68\ud45c.\uac00 \ubd99\uc740 \uac83\uc740 print_string \ud568\uc218 \ub0b4\ubd80\uc5d0\uc11c\ub9cc \uc4f0\ub294 \ub85c\uceec \ub77c\ubca8\uc774\ub77c\ub294 \ub73b\uc785\ub2c8\ub2e4.)<br>This is the destination label that the <code>je<\/code> instruction jumps to. (A period at the beginning of the name indicates a local label used only within the <code>print_string<\/code> function.)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.done<\/code><\/pre>\n\n\n\n<p>2)ret (Return): \uc774 \ud568\uc218\ub97c \ud638\ucd9c\ud588\ub358 \uc6d0\ub798 \uc790\ub9ac(call print_string \ubc14\ub85c \ub2e4\uc74c \uc904)\ub85c CPU \uc2e4\ud589 \uc704\uce58\ub97c \ub3cc\ub824\ubcf4\ub0b4\ub294 \uba85\ub839\uc785\ub2c8\ub2e4.<br>ret (Return): An instruction that returns the CPU&#8217;s execution point to the original location where the function was called (the line immediately following <code>call print_string<\/code>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ret<\/code><\/pre>\n\n\n\n<p>&#8212; \ubcc0\uc218\ub97c \uc120\uc5b8\ubd80\ubd84\uc785\ub2c8\ub2e4.<br>This is the section where variables are declared.<\/p>\n\n\n\n<p>1)\uac01 \ubcc0\uc218\uc5d0 \ubb38\uc790\ub97c 1\ubc14\uc774\ud2b8\uc529 \uc800\uc7a5\ud569\ub2c8\ub2e4.<br>Store one byte of character data in each variable.<\/p>\n\n\n\n<p>2)13\uc740 \uce90\ub9ac\uc9c0 \ub9ac\ud134(\\r)\uc73c\ub85c \ucee4\uc11c\ub97c \ud604\uc7ac \uc904\uc758 \ub9e8 \uc67c\ucabd(\uccab \ubc88\uc9f8 \uce78)\uc73c\ub85c \uc774\ub3d9\uc2dc\ud0b5\ub2c8\ub2e4.<br>13 is the carriage return (\\r), which moves the cursor to the far left (the first column) of the current line.<\/p>\n\n\n\n<p>3)10 \ub77c\uc778 \ud53c\ub4dc(\\n)\ub85c \ucee4\uc11c\ub97c \ud604\uc7ac \uc704\uce58\uc5d0\uc11c \uc815\ud655\ud788 \ud55c \uc904 \uc544\ub798\ub85c \ub0b4\ub9bd\ub2c8\ub2e4.<br>10 Moves the cursor exactly one line down from its current position using a line feed (\\n).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>msg_boot    db '1. Booting MBR...', 13, 10, 0\nmsg_success db '2. Disk read success!', 13, 10, 0\nmsg_error   db 'Disk read failed!', 13, 10, 0<\/code><\/pre>\n\n\n\n<p>&#8212; \uacc4\uc0b0\ub41c \ud69f\uc218\ub9cc\ud07c \ubc14\uc774\ud2b8(db) \uacf5\uac04\uc744 \uc804\ubd80 0\uc73c\ub85c \ucc44\uc6b0\ub77c\ub294 \uba85\ub839\uc5b4\uc785\ub2c8\ub2e4.<br>This command fills the specified number of bytes (db) with zeros.<\/p>\n\n\n\n<p>1) 512\ubc14\uc774\ud2b8\uc5d0\uc11c 510\ubc14\uc774\ud2b8\ub294 \ubd80\ud2b8\ub85c\ub354 \ubc0f \ub370\uc774\ud130\ub97c \uc800\uc7a5\ud558\ub294 \uacf5\uac04\uc785\ub2c8\ub2e4.<br>Of the 512 bytes, 510 bytes are used to store the bootloader and data.<\/p>\n\n\n\n<p>2) \ub098\uba38\uc9c0 \ub9c8\uc9c0\ub9c9 2\ubc14\uc774\ud2b8\ub294 \ubd80\ud305\uac00\ub2a5 \uc5ec\ubd80\ub97c \ud310\ubcc4\ud558\uae30 \uc704\ud55c \uc2dc\uadf8\ub2c8\ucc98\ub85c \uc0ac\uc6a9\ub418\uba70 \ubcf4\ud1b5 16\uc9c4\uc218&nbsp;<code>0xAA55<\/code>\uac00 \ub4e4\uc5b4\uac11\ub2c8\ub2e4. <br>The final two bytes serve as a signature to determine bootability and typically contain the hexadecimal value 0xAA55.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>times 510 - ($ - $$) db 0<\/code><\/pre>\n\n\n\n<p>&#8212; \ubd80\ud305 \ud655\uc778\ucf54\ub4dc \uae30\ub85d \/ Record Boot Verification Code<\/p>\n\n\n\n<p>1) dw\ub294 &#8220;define word&#8221;\uc758 \uc57d\uc790\ub85c, 2\ubc14\uc774\ud2b8(16\ube44\ud2b8) \ub370\uc774\ud130\ub97c \uc120\uc5b8\ud558\uac70\ub098 \uc800\uc7a5\ud560 \ub54c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.<br><code>dw<\/code> stands for &#8220;define word&#8221; and is used to declare or store 2-byte (16-bit) data.<\/p>\n\n\n\n<p>2) \ubd80\ud2b8 \uc139\ud130\uc758 0xaa55\uac12\uc744 \ub9c8\uc9c0\ub9c9\uc5d0 \uae30\ub85d\ud569\ub2c8\ub2e4.<br>Write the value 0xaa55 to the end of the boot sector.<\/p>\n\n\n\n<p>3) \uc774 \uac12\uc774 \uc788\uc5b4\uc57c BIOS\uac00 \ud574\ub2f9 \uc139\ud130\ub97c \ubd80\ud305 \uac00\ub2a5\ud55c \uac83\uc73c\ub85c \uc778\uc2dd\ud569\ub2c8\ub2e4.<br>The BIOS requires this value to recognize the sector as bootable.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dw 0xaa55<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ub514\uc2a4\ud06c\uc5d0\uc11c \ucd94\uac00 \ub370\uc774\ud130 \ub85c\ub4dc\ud558\ub294 \ubc29\ubc95\uc5d0 \ub300\ud55c \uc124\uba85\uc785\ub2c8\ub2e4.This explains how to load additional data from the disk. \ud83d\udc49\ufe0f \ub514\uc2a4\ud06c\ub294 \ud50c\ub85c\ud53c \ub514\uc2a4\ud06c\uc785\ub2c8\ub2e4.The disk is a floppy disk. \ud83d\udc49\ufe0f \uc804\uccb4\ucf54\ub4dc(NASM) \/ Full Code(NASM) \u2714\ufe0f boot.asm &#8212; \uccab \ubc88\uc9f8 \uc139\ud130(512\ubc14\uc774\ud2b8)\ub9cc \ub2f4\ub2f9\ud558\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4.This code handles only the first sector (512 bytes). &#8212; \uba54\ubaa8\ub9ac 0x8000\uc5d0 \ub85c\ub4dc\ub418\uc5b4 \uc2e4\ud589\ub420 \ub3c5\ub9bd\ub41c \ucf54\ub4dc \ud30c\uc77c\uc785\ub2c8\ub2e4. \ub611\uac19\uc774 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,1],"tags":[],"class_list":["post-6060","post","type-post","status-publish","format-standard","hentry","category-os","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=6060"}],"version-history":[{"count":1,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6060\/revisions"}],"predecessor-version":[{"id":6061,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6060\/revisions\/6061"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=6060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=6060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=6060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}