Data labels don't work with ds
Posted: Sat May 30, 2009 11:21 pm
I have written code to print a string using int 0x10. It uses lodsb to get a byte at ds:si. In my initialization code, I set all the segment registers, as follows:
(This is in a stage-1 bootloader, hence the 0x07c0.) The printing code:
It uses lodsb, hence needs the data byte to be at ds:si. However, when I call the print routine, as follows:
it doesn't work. If ds is zeroed (instead of set to 0x07c0), it works fine. Reading this in the bochs debugger, it appears that loadmsg is being replaced by its full address (0x7c3f) rather than just 0x3f, as should be to print properly with lodsb. Confirming this, if I replace the call code above with
it works. At the start of my bootsector, I use
This seems as if it should work. Am I doing something wrong? Why is this being parsed this way?
Code: Select all
cli
mov ax, 0x07c0
mov ds, ax ;; for some reason, this breaks printing the message
mov es, ax
mov fs, ax
mov gs, ax
mov ax, 0x0000
mov ss, ax
mov sp, 0xFFFF
sti
Code: Select all
;; Method: print
;;--------------------------------------
;; ds:si => string to print
;;--------------------------------------
;; Prints a null-terminated string using BIOS interrupt 0x10.
print:
lodsb
or al, al
jz print_end
mov ah, 0x0e
int 0x10
jmp print
print_end:
ret
Code: Select all
mov si, loadmsg
call print
Code: Select all
lea si, [loadmsg - 0x7c00]
call print
Code: Select all
org 0x7c00