can anyone give me a comprehensive description about ORG directive?
When and why is it used in assembly written applications?
Using Nasm on x86 or AMD64.
The ORG statement alters the location counter for the current segment and sets a new origin for subsequent statements. The expression must be a simple relocatable expression with no forward references. Only absolute addresses or symbol values in the current segment may be used.
ORG (abbr. for ORiGin) is an assembly directive (not an instruction). It defines where the machine code (translated assembly program) is to place in memory.
The . org directive advances the location counter in the current section to new-location.
"org <100h>" instructs the compiler with the to-be runtime information to evaluate addresses, as binary image will be loaded with offset (and first 100h bytes possibly to be used for PSP etc. in your context)
ORG is used to set the assembler location counter. This may or may not translate to a load address at link time. It can be used to define absolute addresses, e.g. when defining something like interrupt vectors which may need to be at a fixed address, or it can be used to introduce padding or generate a specific alignment for the following code.
ORG is merely an indication on where to put the next piece of code/data, related to the current segment.
It is of no use to use it for fixed addresses, for the eventual address depends on the segment which is not known at assembly time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With