The assembler recognizes several mnemonics that expand into regular PIC MCU assembly instructions. The mnemonics are
fcall
and ljmp
.
On baseline and mid-range parts, these instructions expand into regular
call
and goto
instructions respectively, but also
ensure the instructions necessary to set the bits in PCLATH (for mid-range devices) or
STATUS (for baseline devices) will be generated when the destination is in another page of
program memory. Whether the page selection instructions are generated, and exactly where
they will be located, is dependent on the surrounding source code. Page selection
instructions can appear immediately before the call
or
goto
, or be generated as part of, and immediately after, a previous
fcall
/ljmp
mnemonic.
On PIC18 devices, these mnemonics are present purely for compatibility
with smaller 8-bit devices and are always expanded as regular PIC18 call
and goto
instructions.
These special mnemonics should be used where possible, as they make
assembly code independent of the final position of the routines that are to be executed. If
the call
or goto
is determined to be within the current
page, the additional code to set the PCLATH bits can be optimized away.
The following mid-range PIC example shows an fcall
instruction in the assembly list file. You can see that the fcall
instruction has expanded to five instructions. In this example, there are two bit
instructions that set/clear bits in the PCLATH register. Bits are also set/cleared in this
register after the call to reselect the page that was selected before the
fcall
.
13 0079 3021 movlw 33
14 007A 120A 158A 2000 fcall _phantom
120A 118A
15 007F 3400 retlw 0
Since fcall
and ljmp
instructions can
expand into more than one instruction, they should never be preceded by an instruction that
can skip, e.g., a btfsc
instruction.
The fcall
and ljmp
instructions assume
that the psect that contains them is smaller than a page. Do not use these instructions to
transfer control to a label in the current psect if it is larger than a page. The default
linker options will not permit code psects to be larger than a page.
On PIC18 devices, the regular call
instruction can be
followed by a “,f
” to indicate that the W, STATUS and BSR registers should
be pushed to their respective shadow registers. This replaces the “,1
”
syntax indicated on the device data sheet.