# Down to the Metal, Chapter 18: a complete boot sector.
# Assemble:  llvm-mc -triple=i386 -x86-asm-syntax=intel -filetype=obj boot.s -o boot.o
#            llvm-objcopy -O binary -j .text boot.o boot.bin
# Run:       qemu-system-i386 -drive format=raw,file=boot.bin,if=floppy

.code16
_start:
    mov ax, 0x07C0
    mov ds, ax              # DS:0 is 0x7C00, where the BIOS loaded us
    mov si, offset msg      # SI = offset of the message
    xor bx, bx              # BIOS: page 0
print:
    lodsb                   # AL = next character, SI = SI + 1
    or al, al               # zero marks the end
    jz done
    mov ah, 0x0E            # BIOS function 0Eh: print the character in AL
    int 0x10                # call the BIOS video service
    jmp print
done:
    hlt                     # sleep until an interrupt...
    jmp done                # ...then sleep again, forever
msg:
    .ascii "Hello from the boot sector!"
    .byte 13, 10, 0
    .fill 510 - (. - _start), 1, 0
    .byte 0x55, 0xAA        # the boot signature
