I am having troubles with the CMP instruction when comparing single words (2 bytes).
The following is my main.asm:
[org 0x7c00]
mov bx, HELLO_MSG
call print_string
mov bx, GOODBYE_MSG
call print_string
jmp $
%include "print_string.asm"
; Data
HELLO_MSG:
    db 'Hello, World!', 0
GOODBYE_MSG:
    db 'Goodbye!', 0
This is the print_string.asm file:
print_string:
    pusha
    mov ah, 0x0e
    loop:
        call print_char
        cmp word [bx], 0
        jne loop
    popa
    ret
print_char:
    mov al, [bx]
    int 0x10
    add bx, 1
    ret
This code prints out the following:
Hello World! Goodbye!Goodbye!
I know that when I add
db 0
in between the HELLO_MSG and the GOODBYE_MSG, the code will work as intended. Can anyone explain why CMP will only work when there are 4 bytes of 0 between the strings?
If anyone is interested in looking at the compiled output, here it is:
bb  23  7c  e8  08  00  bb  31  7c  e8  02  00  eb  fe  60  b4
0e  e8  07  00  83  3f  00  75  f8  61  c3  8a  07  cd  10  83           
c3  01  c3  48  65  6c  6c  6f  2c  20  57  6f  72  6c  64  21
00  47  6f  6f  64  62  79  65  21  00  00  00  00  00  00  00           
00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00
*           
00  00  00  00  00  00  00  00  00  00  00  00  00  00  55  aa
The 55 aa at the end is added by me because I am using this code as a boot loader.
 
    