Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NASM org directive

113 views
Skip to first unread message

Alexander Poquet

unread,
Aug 23, 1998, 3:00:00 AM8/23/98
to
Hi again, thanks for the response to my earlier inquiry regarding GNU
as(1). I was running DOS (I hadn't specified my operating system) but
I have since downloaded NASM and figured it out (a hello world program)
on my own. I used binary output to generate a .COM file, and org 100h to
set the origin to the beginning of the file.

Which brings me to my question: what exactly does the argument to org
refer to? 100h points to the beginning of the program, apparently, but
why 100h? why not 0? Or 10h? What do org 0 and org 10h do? If I have
a program that should begin executing somewhere other than the
beginning, how can I determine the correct argument for org?

I looked at NASM documentation but the org directive didn't have more
than half a page to its credit. If you know of another place where I
might answer my own question, please post.

a...@nospam.best.com (remove nospam)

PS. I've started reading this page with fair frequency, so those of you
nice enough to respond needn't send me a copy via e-mail, though the
gesture was (and is) appreciated. Thanks again.

John S. Fine

unread,
Aug 24, 1998, 3:00:00 AM8/24/98
to Alexander Poquet
Alexander Poquet wrote:

> Which brings me to my question: what exactly does the argument to org
> refer to? 100h points to the beginning of the program, apparently, but
> why 100h? why not 0? Or 10h? What do org 0 and org 10h do? If I have
> a program that should begin executing somewhere other than the
> beginning, how can I determine the correct argument for org?

When DOS loads a .COM file it always uses the first 0x100
bytes of the load segment for a PSP. It always loads the
image directly after the PSP and it always starts executing
it at seg:0x100.

ORG tells NASM that the zero'th byte of its output image
will be loaded at the specified offset in some segment.
This value is effectively added whenever your code refers
to the offset of any point within the image.

You cannot use org to specify another address at which
to begin executing a .COM because:
1) ORG doesn't specify the start of execution (..start does
and .COM files don't support ..start).
2) The DOS loader will load the .COM at seg:0x100 regardless
of where you tell NASM that it ought to be loaded.

There are certain other types of "-f bin" images in which
you might want a different ORG value. For example, if you
are writing a standard bootstrap sector, the BIOS (or earlier
stage bootstrap) will load your image at 0:7C00. If you don't
do an "ORG 0x7C00" within your code then you need a far JMP or
an adjustment to compensate for the offset error.

> PS. I've started reading this page with fair frequency, so those of you
> nice enough to respond needn't send me a copy via e-mail, though the
> gesture was (and is) appreciated.

I always answer both ways unless requested not to. (I only
type the answer once). The person who asked the question gets
the answer faster, and anyone else who is interested sees it
via news.

[Moderator hat on] This is what I call meta-discussion and I
won't approve meta-discussion in clax unless (as in this case)
it is polite, short, and most important: buried under some
on-topic content.
--
http://www.erols.com/johnfine/
http://www.geocities.com/SiliconValley/Peaks/8600/

bowman

unread,
Aug 24, 1998, 3:00:00 AM8/24/98
to
Alexander Poquet wrote:
>
> Which brings me to my question: what exactly does the argument to org
> refer to? 100h points to the beginning of the program, apparently, but
> why 100h? why not 0? Or 10h? What do org 0 and org 10h do?

to amplify a little on John Fine's reply, the 100h thing actually goes
back to CP/M, the 8080/Z80 OS that preceeded DOS. I forget everything
that was stuffed in there. among other things, the command line is at
80h if you are looking for the parameters. As I recall, CP/M buffered
data there too, but its been a long time.


0 new messages