I have been trying to figure out what is the size of the address that can be given with the ORG directive in 8086 (or real mode), since it is a 16-bit environment but 8086 can address 20-bit memory.
Is the address given with ORG supposed to be within the current segment ? NASM's documentation doesn't mention it. What will happen if I do give a 20 bit address ? (I tried this, but there were no assembler errors/warnings. Didn't try to run that though). Will the start/end nibble be truncated or will it be undefined behaviour ?
Size of address given with ORG in 16 bit mode
-
- Posts: 20
- Joined: Wed Jan 29, 2014 11:57 am
Re: Size of address given with ORG in 16 bit mode
Why didn't you try to run the program?
Re: Size of address given with ORG in 16 bit mode
You could try disassembling it with ndisasm to see what was actually produced. Running it is the most effective way of finding out what it does though
- Bender
- Member
- Posts: 449
- Joined: Wed Aug 21, 2013 3:53 am
- Libera.chat IRC: bender|
- Location: Asia, Singapore
Re: Size of address given with ORG in 16 bit mode
The NASM Manual (Chapter 7) gives you this info.Is the address given with ORG supposed to be within the current segment ? NASM's documentation doesn't mention it.
The ORG directive simply adds the number specified to all label references. And yes ORG specifies the offset within a segment.7.1.1 ORG: Binary File Program Origin
The bin format provides an additional directive to the list given in chapter 6: ORG. The function of the ORG directive is to specify the origin address which NASM will assume the program begins at when it is loaded into memory.
For example, the following code will generate the longword 0x00000104:
org 0x100
dd label
label:
Unlike the ORG directive provided by MASM-compatible assemblers, which allows you to jump around in the object file and overwrite code you have already generated, NASM's ORG does exactly what the directive says: origin. Its sole function is to specify one offset which is added to all internal address references within the section; it does not permit any of the trickery that MASM's version does. See section 12.1.3 for further comments.
I think the sane limit of ORG under 16-bit mode should be 64KB (0xFFFF).
BTW Run the program and see what happens, it's always good to run and see the result in front of your eyes.
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
(R3X Runtime VM)(CHIP8 Interpreter OS)
-
- Member
- Posts: 510
- Joined: Wed Mar 09, 2011 3:55 am
Re: Size of address given with ORG in 16 bit mode
In real mode you will never have a 20 bit address*. You will either have a straight 16 bit offset into an implied segment, or a segment:offset pair (32 bits total, 16 bits each for the segment and offset).shahsunny712 wrote:I have been trying to figure out what is the size of the address that can be given with the ORG directive in 8086 (or real mode), since it is a 16-bit environment but 8086 can address 20-bit memory.
Is the address given with ORG supposed to be within the current segment ? NASM's documentation doesn't mention it. What will happen if I do give a 20 bit address ? (I tried this, but there were no assembler errors/warnings. Didn't try to run that though). Will the start/end nibble be truncated or will it be undefined behaviour ?
As others have mentioned, the NASM ORG directive is a 16-bit offset.
*Unless your program calculates that address itself from a segment:offset pair, and then converts it back to a segment:offset pair before using it.
Re: Size of address given with ORG in 16 bit mode
This problem is exactly something that should be solved before running the program. Are you all sure that running the program reliably shows the problem? Or could that be that it accidentally happens to work? Normal code does not rely on the ORG directive as much as one may think.
Analysing the assembler output is a better option unless the behavior can be verified by looking at the documentation.
Analysing the assembler output is a better option unless the behavior can be verified by looking at the documentation.