I have written my own, extremely simple bootsector in x86 assembly (compiled with nasm under windows). Its task is to display a message on screen, read one character, print "OK", and loop endlessly.
Here's the code:
mov ah, 0x0e ; int 10/ah = 0eh -> scrolling teletype BIOS routine
mov al, 'P'
int 0x10
mov al, 'l'
int 0x10
mov al, 'e'
int 0x10
mov al, 'a'
int 0x10
mov al, 's'
int 0x10
mov al, 'e'
int 0x10
mov al, ' '
int 0x10
mov al, 'e'
int 0x10
mov al, 'n'
int 0x10
mov al, 't'
int 0x10
mov al, 'e'
int 0x10
mov al, 'r'
int 0x10
mov al, ' '
int 0x10
mov al, 'a'
int 0x10
mov al, ' '
int 0x10
mov al, 'c'
int 0x10
mov al, 'h'
int 0x10
mov al, 'a'
int 0x10
mov al, 'r'
int 0x10
;newline
mov al, 0x0D
int 0x10
mov al, 0x0A
int 0x10
mov ah, 00h
int 16h
;block until a key is pressed
mov ah, 0x0e
;newline
mov al, 0x0D
int 0x10
mov al, 0x0A
int 0x10
mov al, 'O'
int 0x10
mov al, 'K'
int 0x10
times 510 -( $ - $$ ) db 0 ; Pad the boot sector out with zeros
dw 0xaa55 ; Last two bytes form the magic number ,
; so BIOS knows we are a boot sector.
This works fine, but approx 3 seconds after the "OK" is displayed the screen is covered with weird, pink squares. (Photo here: https://i.sstatic.net/CKDAl.jpg ).
Apparently this is somehow caused by the INT16 routine, as my previous tests which only printed some text didn't cause this.
What could be the reason?
This will run garbage since after printing out OK you run into the endless realm of uninitialized memory. Try adding this before times 510 -( $ - $$ ) db 0
hang:
jmp hang
Or:
cli
hlt
To stop interrupts from happening and then waiting for an interrupt, effectively hanging up the machine.