9.1.2 Rules Concerning Registers

Registers having the same value before and after a function call is not guaranteed for some registers; some registers may change during a function call. Some registers are used for specific purposes according to the option settings. Table 3.27 shows the rules for using registers.

Table 9.1

Rules to Use Registers

Register

Register Value Does Not Change During Function Call

Function Entry

Function Exit

High-Speed Interrupt Register*1

Base Register*2

PID Register*3

R0

Guaranteed

Stack pointer

Stack pointer

R1

Not guaranteed

Parameter 1

Return value 1

R2

Not guaranteed

Parameter 2

Return value 2

R3

Not guaranteed

Parameter 3

Return value 3

R4

Not guaranteed

Parameter 4

Return value 4

R5

Not guaranteed

(Undefined)

R6

Guaranteed

(Value at function entry is held)

R7

Guaranteed

(Value at function entry is held)

R8

Guaranteed

(Value at function entry is held)

O

R9

Guaranteed

(Value at function entry is held)

O

O

R10

Guaranteed

(Value at function entry is held)

O

O

O

R11

Guaranteed

(Value at function entry is held)

O

O

O

R12

Guaranteed

(Value at function entry is held)

O

O

O

R13

Guaranteed

(Value at function entry is held)

O

O

O

R14

Not guaranteed

(Undefined)

R15

Not guaranteed

Pointer to return value
of structure

(Undefined)

ISP

USP

Same as R0 when used as the stack pointer.
In other cases, the values do not change. *4

PC

Program counter*5

PSW

Not guaranteed

(Undefined)

FPSW

Not guaranteed

(Undefined)

ACC

Not guaranteed*6

(Undefined) *6

INTB

BPC

BPSW

FINTV

No change*4

Notes 1.

The high-speed interrupt function may use some or all four registers among R10 to R13, depending on the fint_register option. Registers assigned to the high-speed interrupt function cannot be used for other purposes. For details on the function, refer to the description on the option.

Notes 2.

The base register function may use some or all six registers among R8 to R13, depending on the base option. Registers assigned to the base register function cannot be used for other purposes. For details on the function, refer to the description on the option.

Notes 3.

The PID function may use one of R9 to R13, depending on the pid option. The register assigned to the PID function cannot be used for other purposes. For details on the function, refer to the description on the option.

Notes 4.

This does not apply in the case when the registers are set or modified through an intrinsic function or #pragma inline_asm.

Notes 5.

This depends on the specifications of the instruction used for function calls. To call a function, use BSR, JSR, BRA, or JMP.

Notes 6.

For the instructions that modify the ACC (accumulator), refer to the software manual for the target RX series product.