Hello I am just trying to print 2 messages using functions in assembly language (A simple boot-sector program ), This is my code:
[org 0x7c00]
mov bx,HELLO_MSG
call printer
mov bx,GOODBYE_MSG
call printer
jmp $
printer:
pusha
mov ah,0x0e
mov al,bl
int 0x10
popa
ret
HELLO_MSG:
db 'Hello, World',0
GOODBYE_MSG:
db 'Bye User',0
times 510-($-$$) db 0
dw 0xaa55
I dont know where I am going wrong but the above program is printing some garbage value. Can someone help me out with this please??
First, AL
expects a character to be printed, but you give it a low byte of a pointer to memory address where the first byte of text is stored.
Second, Function 0x0e prints one character in AL
only, so to print the whole string you should iterate through it.
Third, BX
is not the best register to store string pointer. Better use SI
.
Having all that,
pusha
mov ah, 0x0e
__continue:
mov al, [si]
inc si
test al, al ; terminating null reached?
jz __ret ; yes, exit
int 0x10
jmp __continue
__ret:
popa
ret
mov al, [si] / inc si
can be changed to lodsb
for smaller code size