In NASM labels next to each other in memory are printing both strings instead of first one
Your computation of hlen
includes the string Goodbye!
because it comes after the defintion of GOODBYE_MSG
. The expression $ - HELLO_MSG
is the number of bytes between the label HELLO_MSG
and the line where hlen
is defined. That is why your first call to print_string
prints both messages.
Try this order instead:
HELLO_MSG db 'Hello, World!',0
hlen equ $ - HELLO_MSG
GOODBYE_MSG db 'Goodbye!',0
glen equ $ - GOODBYE_MSG
See How does $ work in NASM, exactly? for more details, including this as an example.