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-RL 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)

Register

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

(3)

Return address returned to assembler function

The CC-RL generates codes on the assumption that the return address of a function is stored at the top of the stack. When branching to a C function in an assembly program, the return address of the function must be stored at the top of the stack.

Generally, use a call instruction for branching to C functions, which makes the return address of the function stored at the top of the stack.