14.2 Register Conventions
The 32 general purpose registers contained in the PIC32 are shown in the table below. Some of these registers are assigned a dedicated task by the compiler. The name used in assembly code and the usage is indicated.
Register Number | Software Name | Use |
---|---|---|
$0 | zero |
Always 0 when read. |
$1 | at |
Assembler temporary variable. Do not use the $at register from source code unless you fully understand the implications. |
$2-$3 | v0-v1 |
Return value from functions. |
$4-$7 | a0-a3 |
Used for passing arguments to functions. |
$8-$15 | t0-t7 |
Temporary registers used by compiler for expression evaluation. Values not saved across function calls. |
$16-$23 | s0-s7 |
Temporary registers whose values are saved across function calls. |
$24-$25 | t8-t9 |
Temporary registers used by compiler for expression evaluation. Values not saved across function calls. |
$26-$27 | k0-k1 |
Reserved for interrupt/trap handler. |
$28 | gp |
Global Pointer. |
$29 | sp |
Stack Pointer. |
$30 | fp or s8 |
Frame Pointer if needed. Additional temporary saved register if not. |
$31 | ra |
Return address for functions. |
The PIC32MZ family uses the microMIPS compressed instruction-set architecture. You can
use the micromips
function attribute to compile the function for the
microMIPS compressed mode. This compressed ISA generally results in a ~30% reduction in
overall application code size at the expense of ~2% in performance. The microcontroller
can switch between the MIPS32 and microMIPS modes on a function call. Consult your
device data sheet to determine if your target device supports the microMIPS ISA.
Example function:
#include <xc.h>
void
__attribute__((micromips))
peanut (void)
{
// function code here
}
jals
instruction to call the library function. A
jals
instruction cannot change modes to MIPS32 and upon linking,
you may receive an error, “Unsupported jump between ISA modes; consider recompiling with
interlinking enabled.” In that case, add the -mno-jals
option to the
Alternative Options field in your project properties for xc32-gcc, so it is passed to
the compiler.