Hello everyone!
I am trying to assemble a very simple 'hello world' program in Windows, 16 bit mode, but I am having troubles with it.
The code is very basic. It only show a text in the screen (terminated with 0), then wait for a key press, and exit.
[BITS 16]
ORG 100
INICIO:
mov si, msgHello
xor ax, ax
.teletipo:
lodsb
or al, al
jz .FIN
mov ah, 0x0e
mov bx, 0x07
int 0x10
jmp .teletipo
xor ax, ax
.FIN:
mov ah, 0x01
int 0x16
je .FIN
int 0x20
msgHello db 0x0d, "Hello World!", 0x00
Then I compile it using:
nasm -f bin helloworld.ASM -o hworld.com
When I run it, instead of the Hello World message, I get "rubbish", which means SI is not pointing to what it should.
I tried unassembling it using debug.exe, and it seems that this line
mov si, msgHello
Is assembled as:
mov si, 0x81
Which is completely wrong. If, instead, I load the pointer manually like this:
[BITS 16]
ORG 100
jmp INICIO
msgHello db 0x0d, "Hello World!", 0x00
INICIO:
mov si, 0x102
(...)
It works fine. So I have no idea what's the problem with the assembler not getting the offsets correctly. I'm using NASM version 2.09 (August 27, 2010).