I want to create printl
function that allow me to print string in the ax
register. I am in 16-bit real mode and I can not find any way to print a message. I using int 0x10
to print a single letter.
I try pass argument (string to print) in bx
register, then in a loop print letter by letter and then go back using popa
and ret
. My code didn't really work -- either it created a infinite loop or printed a strange sign.
If you know more efficient way to do it then it's not a problem. I would also like to ask about comment your code if you gave any
This is my code
boot.asm:
start:
mov bx, welcome ;put argument to bx
call printl ;call printl function in sysf.asm
hlt ;halt cpu
welcome db 'Hello', 0
include 'sysf.asm'
times 510 - ($-$$) db 0
db 0x55
db 0xAA
sysf.asm:
;print function
; al is one letter argument (type Java:char)
;
print:
pusha
mov ah, 0x0e
int 0x10
popa
ret ; go back
;printl function
; bx is argument of type Java:String
;
printl:
pusha
jmp printl001
printl001:
lodsb ; I was working with si register but i would like to use bx register
or al,al
jz printl002
mov ah, 0x0e
int 0x10
jmp printl001
printl002:
popa
ret
The
lodsb
instruction loads the byte pointed to by the DS and SI registers but you haven't loaded either with a valid value. Since this a bootloader you also need to use the ORG directive, otherwise the assembler won't know where your code, and therefore thewelcome
message, gets loaded into memory. Try changing the start of of your program to: