Author Topic: nasm vs masm loading ds  (Read 4146 times)

Keith Schincke

  • Guest
nasm vs masm loading ds
« on: February 06, 2005, 04:39:37 AM »
In masm, I am able to write:

mov   ax,   offset line
mov   dx,   ax
mov   ah,   09h
int   21h

In nasm, I have to preload ds:

mov   ax,   data
mov   ds,   ax

mov   ax,   line
mov   dx,   ax
mov   ah,   09h
int   21h

I compiling to an OBJ and linking to an EXE in Wind98.

Does masm and the MS linker preload DS for me?

Thanks for any explaination of the darkness of these assemblers.

Keith

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2364
  • Country: us
Re: nasm vs masm loading ds
« Reply #1 on: February 06, 2005, 07:04:47 AM »
Hi Keith,

I'm astonished that the Masm version works. Is there an "assume" directive preceeding this? AFAIK, the dos loader starts up an MZ executable with ds and es set to the PSP - regardless if the program comes from Masm or Nasm. It's possible to calculate an offset "with respect to" some segment other than the segment of the data (if reachable). Perhaps Masm is doing something like that.

In any case, you *do* need to do it in Nasm. (this applies only to 16-bit dos MZ - .exe - programs - don't try it in Windows... or Linux)

Best,
Frank

Keith Schincke

  • Guest
Re: nasm vs masm loading ds
« Reply #2 on: February 07, 2005, 08:11:00 PM »
Here is the command line I used to compile and link with:
   @ml /Bllink16 /c /nologo test4.asm
   @link16 /nologo test4.obj , test4.exe,,,,

Here is the full code:
.model small
.stack 100h

.data

line   db   "this is the end", 00h, '$', 0

.code


.startup

mov   ax,   offset line
mov   dx,   ax
mov   ah,   09h
int   21h

mov   al,   0
mov   ah,   4ch
int   21h

end

Is it the 16 bit linker that is making things work?

I have seen some example code where pople set ds, sp and other registers at the top of code. Do you know of a list of recommended start instructions that would set up the program enviroment in a reasonable way.

Keith

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2364
  • Country: us
Re: nasm vs masm loading ds
« Reply #3 on: February 07, 2005, 09:19:04 PM »
I'm pretty sure that it's the ".startup" macro that's doing it for you.

mov ax, data
mov ds, ax

Should do it. Add "mov es, ax", if you're going to be using es (implicit destination segreg for stosb, movsb, and other "string" instructions).

The example in the Nasm manual *also* explicitly loads ss and sp. I don't *think* that this is ever necessary - I don't know why it's in there... I never use it.

Best,
Frank