6.1.6.3 Location Counter
The current location within the active program section is accessible via
the symbol $
. This symbol expands to the address of the currently
executing instruction (which is different than the address contained in the program counter
(PC) register when executing this instruction). Thus:
goto $ ;endless loop
will represent code that will jump to itself and form an endless loop. By using this symbol and an offset, a relative jump destination can be specified.
Any address offset added to $
has the native
addressability of the target device. So, for baseline and mid-range devices, the offset is
the number of instructions away from the current location, as these devices have
word-addressable program memory. For PIC18 instructions, which use byte addressable program
memory, the offset to this symbol represents the number of bytes from the current location.
As PIC18 instructions must be word aligned, the offset to the location counter should be a
multiple of 2. All offsets are rounded down to the nearest multiple of 2.
For example:
goto $+2 ;skip...
movlw 8 ;to here for PIC18 devices, or
movwf _foo ;to here for baseline and mid-range devices
will skip the movlw
instruction on baseline or mid-range
devices. On PIC18 devices, goto $+2
will jump to the following
instruction; i.e., act like a nop
instruction.