char:
db 0
mov ah, 0
In assembly, you need to store the data out of the way of the executing code. In this bootloader, execution started at the top where you placed a data item. The CPU will try to interpret it as an instruction but it will fail (most of the time).
I tried printing out a character that was inputted
Once you receive the character as input, you still need to actually store it in the memory labeled char. If you don't, then the instruction mov al, [char]
won't have anything useful to fetch!
Please note that in a bootloader, you are responsible to setup the segment registers. Your code depends on a correct DS
segment register. Because you didn't use an ORG
directive, the correct value for DS
will be 0x07C0.
And the BIOS.Teletype function 0x0E has additional parameters in BH
and BL
. Don't ignore these.
mov ax, 0x07C0
mov ds, ax
mov ah, 0 ; BIOS.GetKeyboardKey
int 0x16 ; -> AL charactercode, AH scancode
mov [char], al
mov bx, 0x0007 ; BH is DisplayPage (0), BL is GraphicsColor (White)
mov ah, 0x0E ; BIOS.Teletype
mov al, [char]
int 0x10
jmp $
char: db 0
times 510-($-$$) db 0
dw 0xAA55