Master the fundamental concepts of boot sector development through this focused micro-challenge.
The BIOS loads the first 512-byte sector of the boot disk to 0x7C00 and jumps there in real mode. Byte 0 starts with a short jump, bytes 510-511 must be 0x55 0xAA, and everything between is your code and data. For example, a teletype loop using INT 0x10 with AH=0x0E can print Hello before the sector hits the mandatory padding.
nasmLoading…
SS:SP (often 0x0000:0x7C00 or 0x9000:0xFFFF)Build with nasm -f bin and test in QEMU with -fda disk.img.
dd if=boot.bin of=disk.img bs=512 count=1 conv=notrunc writes the sector at LBA 0. If QEMU prints no output, verify the boot signature with hexdump -C boot.bin | tail and confirm [ORG 0x7C00] matches the load address. Some BIOS builds leave DL as the boot drive; preserving it in memory helps later disk reads even if this task only prints text.
You will write a 512-byte boot sector that prints a multi-line message and halts. This exercise requires the 0xAA55 signature, BIOS teletype output, and exact sector padding.
The BIOS reads a disk's first sector (512 bytes) to physical address 0x7C00 and jumps to it, but only if the sector ends in the boot signature 55 AA at offset 0x1FE. What else lives in those 512 bytes depends on the kind of sector. A floppy or partition boot sector (VBR) starts with a jump over a BIOS Parameter Block (BPB) that describes the filesystem. A hard disk's Master Boot Record (MBR) starts with code and keeps a four-entry partition table at 0x1BE. Write an analyzer for both.
One or more sectors:
cLoading…
A new sector starts all zero. Bytes are two hex digits. A double-quoted token (without spaces) writes its ASCII characters.
Signature: bytes 510-511 must be 55 aa.
Entry:
EB rel8: a short jump to 0x7C00 + 2 + rel8 (signed).E9 rel16: a near jump to 0x7C00 + 3 + rel16 (signed, 16-bit wrap).VBR if the sector starts with EB xx 90 or E9 xx xx. Print the BPB and nothing else. Its fields are:
.);MBR otherwise. For each of the 4 entries at 0x1BE + 16i with a non-zero type byte (+4):
0x80 is active, 0x00 inactive, anything else invalid;Partition types:
01 FAT12, 04 FAT16 <32M, 05 Extended, 06 FAT16, 07 NTFS/exFAT;0B FAT32 (CHS), 0C FAT32 (LBA), 0E FAT16 (LBA), 0F Extended (LBA);82 Linux swap, 83 Linux, 8E Linux LVM, A5 FreeBSD, EE GPT protective, EF EFI system;cLoading…
Errors:
error: bad offset X, error: bad byte X and error: write past the end of the sector. A sector with any of these prints not analyzed: input errors after its name.error: bad line: LINE (a line outside a sector, or without :).error: end without sector.error: sector NAME is not closed, when a new sector starts or the input ends inside one. The unclosed sector is dropped.Input:
cLoading…
Output:
cLoading…
EB FE is the classic "jump to self" hang at 0x7c00.Hidden tests cover a near jump, a backwards short jump, a FAT32-style BPB with the 32-bit sector count, several partitions with invalid status and multiple active entries, a GPT protective MBR, a missing signature, and malformed input.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it works