Author Topic: ORG Directive  (Read 16690 times)

Offline Orion128

  • New Member
  • Posts: 1
ORG Directive
« on: January 21, 2011, 04:38:21 PM »
Hey Guys,

I am trying to program my 8088 and I am using NASM version 2.10rc3. As you most likely already know, the 8088's startup location is 7F0 which is near the end of my system's memory map.

I need NASM to have the program written to 7F0 and continue the rest of the program at the beginning of memory (0000h).
How would I tell NASM to do this if I am only allowed one ORG directive per source file?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: ORG Directive
« Reply #1 on: January 21, 2011, 08:52:39 PM »
Are you one of the guys discussing 8088s on news:comp.lang.asm.x86 ? If not... jeez there's a lot of interest in 8088s lately! Maybe they're making a comeback!

Anyway, I'm not familiar with 7F0h as a "startup location". I'm not sure what you mean. Power-on? Bootup? I suppose that's a segment?

In any case, the "org" directive, as you probably know, doesn't "cause" your code to be loaded at a certain address, but merely informs Nasm where it will be loaded. It involves only the "offset" part of the address, getting the segments right is up to you (or the OS, if you're loading this code from an OS).

What would you do if you could use two "org"s?

Code: [Select]
org 7F0h
; code to be loaded, by some means, to ????:07F0h
mov ax, target1
target1:
nop
; code to run up to top-of-memory?

org 0
; code to load(?) run(?) at bottom-of-memory
mov ax, target2
target2:
nop

The target1/target2 cruft is just to give you something to disassemble "to see if it worked". This one won't even assemble. But what we can do...

Code: [Select]
org 7C00h
section .text
; code to be loaded, by bios, to 0:7C00h
mov ax, target1
target1:
nop
; code to move following code to 60h:0, say
jmp 60h:0

section code_to_move vstart=0
; code to be loaded to 60h:0
mov ax, target2
target2:
nop

There are other options besides "vstart" that will give you considerable control over arbitrarily named sections - see the Friendly Manual. I question whether you should need to do this, just to program an 8088, but Nasm provides this alternative to "multiple orgs", if you need it.

Best,
Frank