title: Printing a string in assembly using no predefined function
body: <p>I have to define a function in assembly that will allow me to loop through a string of declared bytes and print them using a BIOS interrupt. I'm in 16 bit real mode. This is an exercise on writing a little bootloader from a textbook, but it seems that it was only a draft and it's missing some stuff.
  I have been given the following code:</p>
  
  <pre><code>org 0x7c00
  
  mov bx, HELLO_MSG
  call print_string
  
  mov bx, GOODBYE_MSG
  call print_string
  
  jmp $                ;hang so we can see the message
  
  %include "print_string.asm"
  
  HELLO_MSG:
      db 'Hello, World!', 0
  
  GOODBYE_MSG:
      db 'Goodbye!', 0
  
  times 510 - ($ - $$) db 0
  dw 0xaa55
  </code></pre>
  
  <p>My print_string.asm looks like this:</p>
  
  <pre><code>print_string:
      pusha
      mov ah, 0x0e
  
      loop:
          mov al, bl
          cmp al, 0
          je return
          int 0x10
          inc bx
          jmp loop
  
      return:
          popa
          ret
  </code></pre>
  
  <p>I have some idea of what I'm doing, but the book doesn't explain how to iterate through something. I know how to do it in C but this is my first time using assembly for something other than debugging C code. What happens when I boot through the emulator is that it prints out a couple of lines of gibberish and eventually hangs there for me to see my failure in all it's glory. Hahaha.</p>