Hello,

Iīm still very new to nasm and Iīm still playing around with it.

I wrote a very easy mini dos-program just writing 2 strings to stdout

...



SECTION .data ; data section
m1: db "Hello$" ;
m2: db "Goodbye$"

SECTION .text
        global main
main:
        ;xor-ing really necessary ?
xor dx ,dx
        xor ah, ah
mov dx, m1
mov ah,09h
int 21h

      ;xor-ing really necessary ?
xor dx ,dx
      xor ah, ah
mov dx, m2
mov ah,09h
int 21h



if I compile and run it says hello 2 times instead of hello goodbye.  :sad:

The following code works under linux

section .data

m1: db "starting",10
len1: equ $-m1

m2: db "going down",10
len2: equ $-m2


section .text

global main

main:
mov edx,len1
mov ecx,m1
mov ebx,1
mov eax,4
int 0x80

mov edx,len2
mov ecx,m2
mov ebx,1
mov eax,4
int 0x80

      ;clean exit
mov ebx,0
mov eax,1
int 0x80


Besides the different interrupts for me the main difference is the length param I have to use under linux.

Iīm just wondering what I am doing wrong here... ?? ..
Posted on 2008-09-22 13:07:25 by nicefeature
Are you linking from an object file or producing direct COM files from NASM?
Posted on 2008-09-22 17:59:01 by SpooK
Hi

I am producing a com file direct with

nasm -f bin myfile.asm -o myfile.com

Posted on 2008-09-23 06:32:47 by nicefeature
Xoring sets dx and ah to 0. Yes they are.
Posted on 2008-09-23 21:00:41 by roticv

Xoring sets dx and ah to 0. Yes they are.


In this instance, I would have to say they are not really needed, as MOV instructions immediately follow.
Posted on 2008-09-23 21:09:44 by SpooK

Hi

I am producing a com file direct with

nasm -f bin myfile.asm -o myfile.com




Have you set the program origin to 0x100 (the 64KB mark) as expected by DOS/COM?

Is DS being set to an expected value?
Posted on 2008-09-23 21:12:45 by SpooK
Thanks for the hint. I didnīt explizit initialize ds and didnīt set the origin.
Just found an example for this.

Iīll try it out.

Thank you
Posted on 2008-09-24 06:53:57 by nicefeature
Ok, this works fine.  :P

One more question:

If have the string

m1: db "Hello$"

in my ds.

Iīm playing around and read that all references to data from ds get implicit prefixed with the ds offset.
So why canīt I do the following

mov ax, ds:m1

?

I can do
mov ax,

but this way I would dereference the address of ds+m1 . Thatīs what I thought. Maybe I should start a new thread ..








Posted on 2008-09-24 11:08:06 by nicefeature

Ok, this works fine.  :P

One more question:

If have the string

m1: db "Hello$"

in my ds.

Iīm playing around and read that all references to data from ds get implicit prefixed with the ds offset.
So why canīt I do the following

mov ax, ds:m1

?

I can do
mov ax,

but this way I would dereference the address of ds+m1 . Thatīs what I thought. Maybe I should start a new thread ..


DS is an instruction opcode prefix/modifier, not a symbol.

In the first case, you are saying "place the value of the symbol ds:m1 into ax". All symbols are expected to be resolved as numerical values at assembly time. At most, a relocation entry is added to the object file to help properly calculate and resolve said symbol's address during link/load time, but this does not apply with COM files.

In the second case, you are saying "place the value of the data at address ds:m1 into ax". m1 is a symbol and is thus resolved as a numerical value, but DS turns into a instruction opcode prefix as defined by the x86 architecture instruction set. In a manner of speaking, this case is the equivalent of the byte-ordered pseudo-assembly ds mov ax, WORD and is thus valid.

HtH. -SpooK
Posted on 2008-09-24 22:00:05 by SpooK