0

I was trying to print a string in a boot sector and have the following code:

[org 0x7c00]

mov ah, 0x0e
mov bx, msg
call print

mov bx, msg1
call print

jmp $

print:
        mov al, [bx]
        int 0x10
        inc bx
        cmp al, 0
        jne print
        ret

msg db "hello",0
msg1 db "goodbye",0

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

The output using qemu looks like where the underscores are spaces:

hello_goodbye_

I don't know what I'm missing. The entire point I thought about is to keep looping and printing characters until I find a null character which the strings are terminated with.

I know that I can probably solve the problem with a jump to the end before the bios interrupt call, but I really want to understand why the spaces are being printed after the actual strings.

Any help is extremely appreciated!

  • 1
    It's not a space. You print the zero byte because you only check after printing. – Jester Jul 11 '23 at 00:47
  • @Jester i got my mistake, i don't know how i missed it. i was comparing against al despite incrementing bx. now, i'm wondering why it won't work when comparing with bx: `cmp bx, 0`. i thought that it should compare the value at bx to the null byte, but it seems to send it into an infinite loop? am I missing something? – Aave Tatti Jul 11 '23 at 01:02
  • 2
    Yes, the brackets. You are comparing the address instead of the value. – Jester Jul 11 '23 at 01:07
  • @Jester, that fixed it, thank you so much! – Aave Tatti Jul 11 '23 at 02:52

0 Answers0