4.2.5.1 General-Purpose Register Operands
PIC32M Registers
Register operands can be specified using the appropriate register
number preceded by a dollar sign ($
).The following example shows
assembly source code using register number operands.
.text
# Add Word
li $2, 123
li $3, 456
add $4, $2, $3
If you use the compilation driver (xc32-gcc
) to
preprocess the source code with the CPP-style preprocessor before assembling, you can
take advantage of macros that are provided in the <xc.h>
header file. These macros map conventional register names to the
corresponding register number. The following example shows assembly source code using
conventional register names for operands. See the MPLAB® XC32
C/C++ Compiler User’s Guide for PIC32/SAM MCUs for additional information on
PIC32M register conventions and the compiler's runtime environment.
#include <xc.h>
.text
/* Add Word */
li v0, 123 /* v0 is a return-value register */
li v1, 456 /* v1 is a return-value register */
add a0, v0, v1 /* a0 is an argument register */
Note that these macro names cannot ordinarily be used within assembly code placed inline
with C code using the __asm()
statement.
PIC32C/SAM Registers
r
character. For example the following shows assembly code using
several register
operands. ldr r2, [r7, #4]
ldr r3, [r7]
add r3, r3, r2
rx
registers that have a dedicated purpose. These are listed in the following table.Special symbol | Generic symbol | Usage |
---|---|---|
sp |
r13 |
stack pointer |
lr |
r14 |
link register |
pc |
r15 |
program counter |