Print string using INT 0x10 in bootsector
I want to create a function printl
that allows me to print a string in a register ax
. I am working in 16 bit mode and I cannot find a way to print the message. I am using int 0x10
one letter to print.
I am trying to pass an argument (string to print) in register bx
, then in a loop, print a letter by letter, then return with popa
and ret
. My code didn't really work - either it created an infinite loop or it printed a weird sign.
If you know a more efficient way to do this, this is not a problem. I would also like to ask about the comments of 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
source to share
The command lodsb
loads the byte pointed to by the DS and SI registers, but you have not loaded a valid value. Since this is a loader, you also need to use the ORG directive, otherwise the assembler will not know where you are the code, which means it welcome
is loaded into memory. Try changing the start of your program to:
ORG 0x7c00
start:
push cs
pop ds
mov si, welcome
source to share
According to the documentation for BIOS int 0x10:
Teletype Output: AH = 0Eh, AL = Character, BH = Page Number, BL = Color (only in graphics mode)
If BH
nonzero, it will write to the video page that is not displayed. Unless, of course, you have flipped the display of any page in BH
. You probably want to change your print function:
print:
pusha
mov ah, 0x0e
xor bx, bx ; BX = 0
int 0x10
popa
ret ; go back
If your output causes the screen to scroll, it BP
may be destroyed , although it shouldn't cause problems for your code because it retains all registers.
source to share