bits 16 ; boot sectors run in real mode
- org 7c00h ; boot sector is always loaded at 0x7c00
-
- mov al, 1 ; update cursor after write
- mov bh, 0 ; write to page 0
- mov bl, 00000111b ; attribute: high nibble is foreground (light gray),
- ; low nibble is background (black)
- ; NOTE: in the binary, these will be inverted, so low nibble here will become high nibble in binary and vice versa!
- mov cx, msg1end - msg1 ; size of message
- mov dl, 0 ; column to write to
- mov dh, 0 ; row to write to
- push cs ; push code segment to stack
- pop es ; pop pushed code segment to extra segment, this serves as the base to the string
- mov bp, msg1 ; offset where the string is
- mov ah, 13h ; write string subservice
- int 10h ; call BIOS interrupt 0x10
- jmp msg1end ; jmp to endless loop
- msg1 db "Gotta start somewhere"
- msg1end: jmp msg1end
-
- times 510-($-$$) db 0 ; fill with 0 until 0x1fc is reached
- dw 0xaa55 ; BIOS MBR signature
+ org 7c00h ; boot sector is loaded at 0x7c00
+
+_start
+ mov [boot_drive], dl ; BIOS sets dl to number of boot drive, we don't want to forget this
+
+ mov bp, 8000h ; Move the stack away
+ mov sp, bp
+
+ push cs
+ pop es
+ mov bx, 9000h ; Load at 0000:9000
+ mov dh, 2 ; Load 5 sectors
+ mov dl, [boot_drive] ; Load from boot drive
+ call read_sectors
+
+ mov dx, [9000h] ; Print value at 9000h, should be 0xDEAD
+ call print_word
+ mov dx, [9000h + 512] ; Print value at 9200h, should be 0xBEEF
+ call print_word
+
+ jmp $ ; Endless loop
+
+%include "print.s"
+%include "disk.s"
+
+boot_drive resb 1 ; Reserve 1 byte for boot drive number
+
+times 510-($-$$) db 0 ; fill with 0 until 0x1fc is reached
+dw 0AA55h ; BIOS MBR signature
+
+times 256 dw 0DEADh ; Fill in 2nd sector with 0xDEAD
+times 256 dw 0BEEFh ; Fill in 3rd sector with 0xBEEF