×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Segments with Nasm

Segments with Nasm

Segments with Nasm

(OP)
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

RE: Segments with Nasm

Hi,
Why don't you read the documentation?

Greetings,

Wouter Dijkslag
 
http://www.wody.demon.nl
 

RE: Segments with Nasm

(OP)
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

RE: Segments with Nasm

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
 
http://www.wody.demon.nl
 

RE: Segments with Nasm

(OP)
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

RE: Segments with Nasm

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
 
http://www.wody.demon.nl
 

RE: Segments with Nasm

(OP)
Many thanks Wody. It worked a treat.

ASCII silly question, get a silly ANSI

RE: Segments with Nasm

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!

---

RE: Segments with Nasm

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
 
http://www.wody.demon.nl
 

RE: Segments with Nasm

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

RE: Segments with Nasm

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

RE: Segments with Nasm

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...

"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close