Here’s where it gets weird: depending on where I place the %include directive, I get completely different outputs.
Here's the code and all the placements of the include with the different o/p it gives:
Code: Select all
org 0x7C00
bits 16
%include "printer.asm" ; placing include here prints "S" (probably garbage)
mov bx, GREETING
call print
%include "printer.asm" ; placing include here prints the GREETING message twice (Hello WorldHello World)
loop:
jmp loop
%include "printer.asm" ; placing include here prints the GREETING message as expected (Hello World)
GREETING:
db "Hello World", 0
times 510-($-$$) db 0
dw 0xaa55
I understand that NASM is a flat binary format and memory layout matters, but I thought %include is just a textual paste. Why is it behaving this way?
Is the string or code overlapping? Is NASM putting instructions and data in conflicting places? What’s the correct way to organise includes and data to prevent this?
This is the printer.asm file (included file):
Code: Select all
; prints contents stored at BX
print:
pusha
mov ah, 0x0e ; tty mode
start:
mov al, [bx]
cmp al, 0
je done
int 0x10
add bx, 1
jmp start
done:
popa
ret