Microchip Technology SW006023-2 Datenbogen
MPLAB
®
XC32 C/C++ COMPILER
USER’S GUIDE
2012 Microchip Technology Inc.
DS51686E-page 121
Chapter 9. Register Usage
9.1
INTRODUCTION
This chapter examines registers used by the compiler to generate assembly from
C/C++ source code.
C/C++ source code.
9.2
REGISTER USAGE
The assembly generated from C/C++ source code by the compiler will use certain reg-
isters that are present on the PIC MCU device. The compiler assumes that nothing
other than code it generates can alter the contents of these registers, but an extended
assembly language format can be used to indicate to the compiler registers used in
assembly code so that code can be adjusted accordingly.
isters that are present on the PIC MCU device. The compiler assumes that nothing
other than code it generates can alter the contents of these registers, but an extended
assembly language format can be used to indicate to the compiler registers used in
assembly code so that code can be adjusted accordingly.
9.3
REGISTER CONVENTIONS
The 32 general purpose registers contained in the PIC32 are shown in Table 9-1. Some
of these registers are assigned a dedicated task by the compiler. The name used in
assembly code and the usage is indicated.
of these registers are assigned a dedicated task by the compiler. The name used in
assembly code and the usage is indicated.
TABLE 9-1:
REGISTER CONVENTIONS
Register
Number
Software
Name
Use
$0
zero
Always 0 when read.
$1
at
Assembler temporary variable.
$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.
Values not saved across function calls.
$16-$23
s0-s7
Temporary registers whose values are saved across function
calls.
calls.
$24-$25
t8-t9
Temporary registers used by compiler for expression evaluation.
Values not saved across function calls.
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.
not.
$31
ra
Return address for functions.