NASM org directive
- From: "cheeky" <spamtrap@xxxxxxxxxx>
- Date: 22 Jun 2006 06:27:17 -0700
I was studying programming BIN format which will be executed not based
on any operating system. I wrote a boot sector program which loads a
small size of another program at RAM 0x10000.
My first question is how NASM ORG directive works. I really wonder how
it works. When I read the NASM manual, it explains it to me that it is
used to specify the origin address from the segment so that NASM knows
there. For example, the directive [org 0x100] in .COM format says the
actual code begins 0x100 byte away from where the CS register points
to. That's what I studied. I found the operand label address value was
added by offset when I change the direcive operand. I would like to
know something inside and more details. How does offset or displacement
changes?
And the second question is something about the program loaded at RAM
physical address 0x10000. Let me show some code snippets.
[org 0]
[bits 16]
start:
mov ax, cs
mov ds, ax
xor ax, ax
mov ss, ax
Now, CS and DS have the same value, but the next two lines don't make
sense to me. What will happen internally when the SS segment of that
program has zero? Of course, this program has a procedure, but it works
fine. It has no problem during push and pop action. I really wonder
where the stack segment points to. Which direction does stack grow?
My last question is how I can debug these BIN format prgoram without
any help from OS.
The book I'm studying does not illustrate much, so I've got a lot of
problems... Please, help me understand. Thank you in advance.
.
- Follow-Ups:
- Re: NASM org directive
- From: spamtrap
- Re: NASM org directive
- From: Frank Kotler
- Re: NASM org directive
- From: Bjarni Juliusson
- Re: NASM org directive
- Prev by Date: Re: .EXE -> .ASM -> .EXE
- Next by Date: Re: .EXE -> .ASM -> .EXE
- Previous by thread: .EXE -> .ASM -> .EXE
- Next by thread: Re: NASM org directive
- Index(es):