0

I am trying to implement a print function in an external file given this code:

[ org 0x7c00 ]

mov bx , HELLO_MSG
call print_string

mov bx , GOODBYE_MSG
call print_string

jmp $

%include "print_string.asm"

HELLO_MSG:
db "Hello , World !" , 0 ;

GOODBYE_MSG:
db "Goodbye !", 0

times 510 -( $ - $$ ) db 0
dw 0xaa55

The function I wrote looks like this:

print_string :
pusha
mov ax, bx
mov ah , 0x0e
int 0x10
popa
ret

But it doesn't work. I guess it's because I am using the wrong registers... but I am a little confused, because in previous examples in the tutorial, the character to be printed is first moved to al and in the print function only this is used:

mov ah , 0x0e
int 0x10
ret

But since here, bx is used, I can't just print what's in al, right?

Some help would be highly appreciated!!

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
user3813234
  • 1,580
  • 1
  • 29
  • 44
  • Although I don't know what the assignment is, I can guess based on the code that a previous assignment/exercise had you print a single character to the screen `int 0x10 / ah=0x0e` does just that (it only prints one character though). It seems you now need to display a string where the address is passed in `bx`. A string may not be able to fit in a register so you pass the address. To print a string you would have to loop through a string (ending with nul `0`) and print each character individually (moving each character to `al`) as you go along. – Michael Petch Oct 03 '15 at 20:54
  • If you are writing code for an 80286 or greater there is another option and that is to use `int 0x10 / ah = 13h`. More about that video interrupt can be found [here](http://www.ctyme.com/intr/rb-0210.htm) . I have a suspicion though that if this is an assignment that your professor intended you to manually traverse a string in memory printing each character. – Michael Petch Oct 03 '15 at 20:58
  • If you are writing a bootloader I highly suggest that you set the _DS_ register (and even _ES_) to 0 (since you use an ORG of 7c00h). Although it may work on the emulator you using it probably won't work on real hardware or other emulators and VMs. I wrote some general tips for writing bootloaders in this [Stackoverflow answer](http://stackoverflow.com/a/32705076/3857942) . – Michael Petch Oct 03 '15 at 21:03
  • Possible duplicate of [Printing a string in assembly using no predefined function](http://stackoverflow.com/questions/18731047/printing-a-string-in-assembly-using-no-predefined-function) . In particular this [answer](http://stackoverflow.com/a/18731235/3857942) may be the type of code you'd be looking at. – Michael Petch Oct 03 '15 at 21:10

0 Answers0