Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NASM newbies

Status
Not open for further replies.

BagelBob

Programmer
Apr 13, 2001
7
0
0
US
I'm trying to learn NASM, starting with 16 bit DOS, but I'm
not having much luck with sources. The official NASM site
has a beginner's site, but it doesn't work. Does anyone have any suggestions? I would hate to waste peoples' time
posting beginner questions on a pro site. Any references
would be appreciated.
 
Are you saying you are attempting to learn how to use the NASM assembler or how to use Assembly (the language)... the compiler can be downloaded and there should also be documentation on the site that you can also download. If you know how to "code for" MASM, NASM is a bit fickle (fewer directives, some slight syntax differences) but no more difficult than adjusting to AT&T syntax (gas)... post newbie questions please! Often those are the most interesting.
 
"gas" is the assembler ultimatum
Do not rejoice that ur code works.
it might be a special case of an error :-(
 
To Twistor: Actually, both. Here's my current problem.
Attempting to assemble a simple, sort of "Hello World",
program, the NASM16 assembler is telling me that my segment
names are "unrecognized" and that my '..start:' label is an
'unrecognized special symbol'. O.K., so I'm doing something
wrong. But, I can't seem to find any answer as to what in
the NASM manual. In addition I have some sample source code
that came with the text I'm using and it won't assemble
either - same errors! But, I know the source code is good
because the obj and exe files came along with the source.
Could I have an os problem?

To Sarnath: Maybe so, but at my level it shouldn't make any
difference and (as an old Fortraner) Intel syntax feels more
comfortable. Besides, for NASM I have a 'textbook' which
doesn't assume a PhD in CS.
 
--- hello.asm (for DOS/Windows & NASM)
SEGMENT .CODE
..start:
push cs
pop ds
mov ah,9
mov dx,hello
int 21h
mov ah,4ch
int 21h
ret

hello db 'Hello, world!',13,36
---
Assemble with
nasm -o hello.obj -f obj hello.asm
Link with your favourite linker
Wouter Dijkslag

 
I think "..start" is the problem.
Jus say "start:"
That would do..
If this works, vote me as the TIP Master of the week..
ha ha ha...
just joking..

Sarnath
Do not rejoice that ur code works.
it might be a special case of an error :-(
 
Hello,
No, this does not work. Since the .OBJ file-format is used, ..start must be used as the startup-symbol.
If you do not do this, at link-time the linker will complain about no progam entry point, because NASM doesn't know what other label to use, since it doesn't support something like 'end start' like TASM and MASM etc support.
The code as I have shown above is 100% correct.
Wouter Dijkslag

 
To Wody and Sarnath: Thank you ladies and/or gentlemen; I
think I have resolved the problem. I may have been (I hang
my newbi head in shame) misspecifying the output format as
bin and nasm, thinking I was trying to create a COM file,
didn't like the segment names or the start label. My IDE
(nasmide) appears to be under the same impression - indicating only that I dont know how to use it.
Now I have a new problem, having to do with the stack. Like
Wednesday's child, newbis are full of woe. I'm going to
start a new thread for it.

Thanks again.
 
--- hello.asm (for DOS/Windows & NASM) (obj->com version)
SEGMENT .CODE
resb 100h
..start:
mov ah,9
mov dx,hello
int 21h
ret

hello db 'Hello, world!',13,36
---
Assemble with
nasm -o hello.obj -f obj hello.asm
Link with your favourite linker

--- hello.asm (DOS/Windows & NASM) (bin fileformat version)
org 0100h
start:
mov ah,9
mov dx,hello
int 21h
ret

hello db 'Hello, world!',13,36
---
Assemble with
nasm -o hello.com -f bin hello.asm


Wouter Dijkslag

 
;The previous examples require a linker. It creates a simple 16-bit dos .com file.
;use: nasmw -fbin hello.asm -o hello.com

org 100h
start:
jmp begin
data:
msg db "Hiya there!$"

begin:
lea dx, [msg] ; load offset of string into dx register
mov ah, 09 ; set ah to function 9 "print $-terminated string"
int 21h ; call dos services

mov ax, 4c00h ; set ah to 0 for "exit fucntion"
int 21h ; call dos services

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top