Reputation: 11
So I was following with a tutorial on how to make an os and I want to make a program that takes a single char and prints it but it doesn't work.
Heres the source code
[org 0x7c00]
mov ah, 0
int 0x16
mov al, [test]
mov bx, test
call print
jmp $
print:
mov ah, 0x0e
loop:
cmp [bx], byte 0
je exit
mov al, [bx]
int 0x10
inc bx
jmp loop
exit:
ret
test:
db 0
times 510-($-$$) db 0
dw 0xaa55
Upvotes: 1
Views: 164
Reputation: 39166
As @Jester pointed out in a comment, you need to store the ASCII output from the BIOS.GetKeyboardKey function 00h in the test variable and not the other way round.
Now if you correct this, it's possible and probable that your program will seem to work fine, but we should not cheer too soon! Since you didn't setup the DS
segment register, it can easily be true that the instruction mov [test], al
will overwrite some other memory location that you just won't notice unless something crashes...
You need a correct DS
to address the variable test.
The BIOS.Teletype function 0Eh that is used in the print subroutine expects the DisplayPage argument in BH
and the (graphics) color in BL
. You should never use BX
to point to the message! Use SI
or DI
for this.
Also be aware that your print code expects a zero-terminated string, but you don't actually provide that zero!
This is a corrected version of the code:
[org 0x7C00]
xor ax, ax
mov ds, ax
mov ah, 00h ; BIOS.GetKeyboardKey
int 0x16 ; -> AX
mov [test], al ; Store ASCII in zero-terminated string
mov di, test
call print
jmp $
print:
mov bx, 7 ; BH=0 DisplayPage, BL=7 Color White
.loop:
mov al, [di]
cmp al, 0
je .exit
mov ah, 0x0E ; BIOS.Teletype
int 0x10
inc di
jmp .loop
.exit:
ret
test:
db 0, 0
times 510-($-$$) db 0
dw 0xAA55
Upvotes: 2