Author Topic: Having troubles with a very simple Hello World program  (Read 4888 times)

Offline NinjiHaku

  • Jr. Member
  • *
  • Posts: 4
Having troubles with a very simple Hello World program
« on: October 12, 2013, 01:27:03 PM »
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.

Code: [Select]
[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:

Quote
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

Code: [Select]
mov si, msgHello
Is assembled as:

Code: [Select]
mov si, 0x81
Which is completely wrong. If, instead, I load the pointer manually like this:

Code: [Select]
[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).

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Having troubles with a very simple Hello World program
« Reply #1 on: October 12, 2013, 04:03:28 PM »
DEBUG has an advantage (kinda) in that it knows only hex. You've got "org 100" decimal. "org 100h" or "org 0x100" should fix you up.

Best,
Frank


Offline NinjiHaku

  • Jr. Member
  • *
  • Posts: 4
Re: Having troubles with a very simple Hello World program
« Reply #2 on: October 12, 2013, 05:05:47 PM »
DEBUG has an advantage (kinda) in that it knows only hex. You've got "org 100" decimal. "org 100h" or "org 0x100" should fix you up.

Best,
Frank

It did work. I forgot that every number in NASM must be specified as hex if I want to use hex values. Thank you!