6.1.9.34 Org Directive
The ORG
directive changes the value of the location
counter within the current psect.
Note: The much-abused
ORG
directive moves the
location counter to an offset relative to the base address of the current psect, not to an
absolute address. Only if the psect in which this directive is placed is marked with the
abs
and ovrld
flags will the directive argument
represent an absolute address. To place objects at an absolute address, place them in a
psect of their own and link this psect at the required address using the linker's
-P
option (see P: Position Psect). The ORG
directive is not commonly required in
programs.The argument to
ORG
must be either an absolute value, or
a value referencing the current psect. In either case, the current location counter is set
to the value determined by the argument. It is not possible to move the location counter
backward. For example:ORG 100h
will move the
location counter to the beginning of the current psect plus 0x100. The actual location will
not be known until link time. If the ORG
directive is within a psect that
has multiple components in the same module, the offset is calculated from the start of the
psect, once all the psect components with the same name have been collated. For example, in
the following:psect text,class=CODE,delta=2
begin:
btfsc status,2
...
psect text,class=CODE,delta=2
next:
ORG 200h
movlw 20
the movlw
instruction will be placed 0x200 words
after the label begin
, not 0x200 words after the label
next
. The offset imposed by this directive is not affected by psects
with the same name in other modules.In order to use the
ORG
directive to set the location
counter to an absolute value, the directive must be used from within an absolute, overlaid
psect. For example:PSECT absdata,abs,ovrld
ORG 50h
;this is guaranteed to reside at address 50h