The problem (I think) is that Nasm's "-f obj" produces a linkable object file, not a ready-to-run executable. Using "-o a.exe" will cause the file to be named .exe, but it isn't one! I'm surprised that it runs at all.
If you assemble it with:
nasm -f obj a.asm
... without the "-o" switch, Nasm will ("should") produce "a.obj" which will then need to be linked into an executable. If you've used Tasm, you've probably got Tlink, and probably know the proper command line. I think just:
tlink a.obj
would work, although you may want to put some (3?) commas after it to avoid having to hit "enter" to accept the defaults. Other linkers would work, too. Alink is good...
http://alink.sf.netBe aware that the "usual" Microsoft "link" is for 32-bit code - you'll need the 16-bit version! If the banner says "incremental linker", that's the wrong version - you want "segmented linker".
It might be easier to make a .com file - Nasm will do this directly with no linker needed. You'll need some minor changes to your code...
; neither of these is necessary
; they both do the same thing
; won't hurt...
use16
bits 16 ;for 16 bits program
; this doesn't "cause" our program to be loaded at 100h
; dos does that with a .com file
; but we need to tell Nasm that this is so.
org 100h
; ".data", not "data" is a "known" segment name
; in "-f bin" output format
; this merely moves "segment .data" after ".text"
; which we need, as a .com file starts at the top
segment .data
hello: db 'hello, world','$'
; don't need this for "-f bin"
; stack will be at top of our one-and-only segment
; segment _stack stack
; resb 64
; stacktop:
; ".text" is the "known" segment name in "-f bin"
segment .text
; only "-f obj knows "..start"
; a .com file will start at the beginning of ".text"
; ..start:
; don't need/want this for "-f bin"
; segment registers are set by dos in a .com file
; mov ax,data
; mov ds,ax
; if you've got the stack declared correctly
; which you do (did)
; you don't even need this in an .exe
; yeah, I know the example in the manual shows it
; but dos loads ss:sp for us
; mov ax,_stack
; mov ss,ax
; mov sp,stacktop
; from here, just the same.
mov dx,hello
mov ax,0900h
int 21h
mov ax,4c00h
int 21h
Assemble that with:
nasm -f bin -o a.com a.asm
Note that you do need the "-o" switch in "-f bin" mode, or Nasm will name our gem just "a", which dos won't recognise. Could rename it to "a.com", too. Actually, we could name it "a.exe" and it would still work - dos looks for the "MZ" signature, and runs it as a .com file if it's not there...
The only disadvantage to a .com file is that you can't link multiple objects together, which you don't need for this, but might want later...
If you can't get it working with one or another of these methods, get back to us. As you say, it should be "easy"... (but sometimes the "easy" things aren't!).
Best,
Frank