I am having an issue while programming in NASM. I am learning how to develop an OS purely in assembly and have started by creating a boot loader.
My goal currently is to print "Hello, World!" and "Goodbye!" using the the BIOS interrupt 0x10.
The issue I seem to be having occurs while printing values on the screen. Two labels appear to be next to each other in memory causing printing one string to print the contents of the other string.
Why isn't hlen
stopping the loop at the end of the first string?
[org 0x7c00]
mov ah, 0x0e
mov bx, HELLO_MSG
mov cx, hlen
call print_string
mov bx, GOODBYE_MSG
mov cx, glen
call print_string
jmp $
%include "print_string.asm"
HELLO_MSG db 'Hello, World!',0
GOODBYE_MSG db 'Goodbye!',0
hlen equ $ - HELLO_MSG
glen equ $ - GOODBYE_MSG
times 510-($-$$) db 0
dw 0xaa55
BUGS:
Prints goodbye message twice
This is due to the HELLO_MSG printing
Hello, World!
andGoodbye!
. I believe this occurs because theHello_MSG
label is right next to theGOODBYE_MSG
label in memory
;;;print_string.asm
print_string: ;cx = string length
;bX = string label - memory offset
; -- if you want the data at a memory adress use [bx]
mov al, [bx]
int 0x10
inc bx
loop print_string
ret