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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Segments with Nasm

Status
Not open for further replies.

modalman

Programmer
Feb 14, 2001
156
GB
Hi. I have just started using nasmw and I need to know the syntax to specify the segments within the assembler. Many thanks. ASCII silly question, get a silly ANSI
 
I have read and tried the syntax mentioned in the documentation and it doesn't work. Could it be something to do with the fact that I am using nasmw instead of nasm? ASCII silly question, get a silly ANSI
 
Hi,

Nasmw is the same as nasm, only nasmw is a Windows program.

Example that uses segments:

;- hello.asm - (DOS exe file) --- cut here
SECTION CODE

..start:
mov ax,DATA
mov ds,ax
mov ah,9
mov dx,text
int 21h
mov ax,4c00h
int 21h

SECTION DATA

text db 'Hello,World',13,10,36
;- hello.asm - (DOS exe file) --- cut here

Assemble with
Nasm -o hello.obj -f obj hello.asm

Link with your favourite linker
Wouter Dijkslag

 
Thanks for the code Wody. I'm still getting the following error message when its assembling:

segment name 'CODE' not recognised
segment name 'DATA' not recognised

Any ideas?
If its any help I assembled using this:

nasmw -f bin hello.asm -o hello.obj

Sorry to be pain. Many thanks
ASCII silly question, get a silly ANSI
 
Hello,

Refer to section 5.2 of the documentation why it doesn't work. Specifically, you are using the BIN output format and not using the OBJ file format. When you use the BIN format, you would get something lke

;- hello.asm - (Nasm BIN DOS com file) --- cut here
SECTION .text

org 0x100

start:
mov ah,9
mov dx,text
int 21h
mov ax,4c00h
int 21h

SECTION .data

text db 'Hello,World',13,10,36
;- hello.asm - (Nasm BIN DOS com file) --- cut here

Compile with:
nasmw -f bin hello.asm -o hello.com

Greetings,
Also read section 6.1 about the BIN file format.
Wouter Dijkslag

 
Many thanks Wody. It worked a treat. ASCII silly question, get a silly ANSI
 
Hi woody,

I tried the hello, world program and
I have warning of 'no stack' during link.

How do I set up the stack? Thanks!

---

 
Hello,

You receive the no stack warning because this is a COM program, not an EXE program. A COM program has no stack-information in itself, it is set up by the operating-system (after which you can change it, if you want off course, but that is not the purpos). You have to use EXE2BIN or EXE2COM or something to make the real program, or not link it to EXE but to COM file format.

Wouter Dijkslag

 
Be careful when making a .COM program (as opposed to .EXE). The CS, DS, and SS segment registers all point to the same area of memory, so if you use too much stack space, it will eventually start to trample your code. The stack pointer is initially at the top of the code segment (64KB). For example: if you have 10K of code and data, the maximum stack space available is 54KB.

Tip: when posting a question like this, please tell us what you are doing. Are you using it for Visual C++? DJGPP? DOS COM file? Are you going to link it? With what?

Doug Gale
 
The best way to make a COM file with Nasm is to use the 'bin' format, and put ORG 0x100 near the top of your source file. If you make the output file have a .COM extension, it will be directly usable without linking.

Doug Gale
 
EXE2BIN hasn't been available with DOS or any OS Micro$oft has released for a long time. Fortunately its functionality is present in a program that Micro$oft still packages with Windows 98, debug. Here's an alternative .bat file.

rem exe2bin.bat
@echo off
del exe2bin.scr
echo N file.bin >>exe2bin.scr
echo W >>exe2bin.scr
echo Q >>exe2bin.scr
debug file.exe <exe2bin.scr
:end

'course you need to replace file.bin and file.exe with the proper filenames of the program... and probably you can just write the script file separately... &quot;Information has a tendency to be free. Which means someone will always tell you something you don't want to know.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top