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.
Condition/Instruction | PC Modification | Software 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 * slit20 | None |
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 = lit24 | PC + 4 is PUSHed on the stack(2) |
CALL Wn (Call Subroutine Indirect) | PC = Wn | PC + 4 is PUSHed on the stack(2) |
GOTO Expr(1) (Unconditional Jump) | PC = lit24 | None |
GOTO Wn (Unconditional Indirect Jump) | PC = Wn | None |
RCALL Expr(1)(Relative Call) | PC = (PC + 4) + 2 * slit20 | PC + 4 is PUSHed on the stack(2) |
RCALL Wn (Computed Relative Call) | PC = (PC + 4) + 2 * Wn | PC + 4 is PUSHed on the stack(2) |
Exception Handling | PC = Address of the exception handler (read from vector table) | PC + 4 is PUSHed on the stack(3) |
PC = Target REPEAT instruction ( | PC not modified (if REPEAT active) | None |
Note:
|