3.3 Program Addressing Modes

The dsPIC33A devices have a 24-bit Program Counter (PC). The PC addresses the 24-bit wide program memory to fetch instructions for execution and it may be loaded in several ways. Instructions are either 16-bit, 32-bit or 64-bit entities; therefore, the PC is incremented by 2, 4 or 8 during sequential 16-bit, 32-bit or 64-bit instruction execution, respectively.

Several methods may be used to modify the PC in a non-sequential manner and both absolute and relative changes may be made to the PC. The change to the PC may be from an immediate value encoded in the instruction or a dynamic value contained in a Working register. For exception handling, the PC is loaded with the address of the exception handler, which is stored in the Interrupt Vector Table (IVT). When required, the software stack is used to return scope to the foreground process from where the change in program flow occurred.

Table 3-5 summarizes the instructions which modify the PC. When performing function calls, it is recommended that RCALL be used instead of CALL, since RCALL only consumes one word of program memory.

Table 3-5. Methods of Modifying Program Flow
Condition/InstructionPC ModificationSoftware Stack Usage
Sequential Execution

PC = (PC + 2) / (PC + 4) / (PC + 8)

Depending on size of the instruction.

None
BRA Expr(1)

(Branch Unconditionally)

PC = PC = (PC + 4) + 2 * slit20None
BRA Condition, Expr(1)

(Branch Conditionally)

PC = PC + 4 (condition false)

PC = (PC + 4) + 2 * slit20 (condition true)

None
CALL Expr(1)

(Call Subroutine)

PC = lit24PC + 4 is PUSHed on the stack(2)
CALL Wn

(Call Subroutine Indirect)

PC = WnPC + 4 is PUSHed on the stack(2)
GOTO Expr(1)

(Unconditional Jump)

PC = lit24None
GOTO Wn

(Unconditional Indirect Jump)

PC = WnNone
RCALL Expr(1)

(Relative Call)

PC = (PC + 4) + 2 * slit20PC + 4 is PUSHed on the stack(2)
RCALL Wn

(Computed Relative Call)

PC = (PC + 4) + 2 * WnPC + 4 is PUSHed on the stack(2)
Exception HandlingPC = Address of the exception handler

(read from vector table)

PC + 4 is PUSHed on the stack(3)
PC = Target REPEAT instruction

(REPEAT Looping)

PC not modified (if REPEAT active)None
Note:
  1. For BRA, CALL and GOTO, the Expr may be a label, absolute address or expression, which is resolved by the linker to a 20-bit or 24-bit value (slit20 or lit24). When representing an address offset value, Expr can also be indicated by using a “.” and a sign, “+” or “-”. For example, the expression, “.+2”, means an address offset of +2 (i.e., the next instruction address relative to the current position of the Program Counter). See Instruction Descriptions for details.
  2. After CALL or RCALL is executed, RETURN or RETLW will POP the Top-of-Stack (TOS) back into the PC.
  3. After an exception is processed, RETFIE will POP the Top-of-Stack (TOS) back into the PC.