Everything
9.3 Calling of C Language Routine from Assembly Language

This section explains the points to be noted when calling a C function from an assembler function.

(1)

Stack frame

The CC-RH generates codes on the assumption that the stack pointer (SP) always indicates the lowest address of the stack frame. Therefore, set SP so that it indicates the higher address of an unused area of the stack area before branching from an assembler function to a C function. This is because the stack frame is allocated towards the lower addresses.

(2)

Work register

The CC-RH retains the values of the register for register variable before and after a C function is called but does not retain the values of the work registers. Therefore, do not leave a value that must be retained assigned to a work register.

The register for register variable and work registers that can be used differ depending on the register mode.

Table 9.3

Registers for Register Variables

Register Modes

Register for Register Variable

22-register mode

r25, r26, r27, r28, r29

32-register mode

r20, r21, r22, r23, r24, r25, r26, r27, r28, r29

Table 9.4

Work Register

Register Modes

Work Register

22-register mode

r10, r11, r12, r13, r14

32-register mode

r10, r11, r12, r13, r14, r15, r16, r17, r18, r19

(3)

Return address returned to assembler function

The CC-RH generates codes on the assumption that the return address of a function is stored in link pointer lp (r31). When execution branches to a C function, the return address of the function must be stored in lp.

Execution is generally branched to a C function using the jarl instruction.