beautypg.com

Calling conventions, Function call mechanism: dynamic frame, See the – Zilog Z8F0130 User Manual

Page 239

background image

UM013037-1212

Calling Conventions

Zilog Developer Studio II – Z8 Encore!

User Manual

215

Calling Conventions

The Z8 Encore! C-Compiler imposes a strict set of rules on function calls. Except for spe-
cial run-time support functions, any function that calls or is called by a C function must
follow these rules. Failure to adhere to these rules can disrupt the C environment and
cause a C program to fail.The following sections describe the calling conventions:

Function Call Mechanism: Dynamic Frame

– see page 215

Function Call Mechanism: Static Frame

– see page 216

Function Call Mechanism: Register Parameter Passing

– see page 218

Return Value

– see page 220

Special Cases

– see page 220

Function Call Mechanism: Dynamic Frame

A function (caller function) performs the following tasks when it calls another function
that has a dynamic call frame (called function):

1. Push parameters on the stack in reverse order (the right-most declared argument is

pushed first, and the left-most is pushed last). This places the left-most argument on
top of the stack when the function is called.

2. Then call the function. The call instruction pushes the return address on the top of the

stack.

3. On return from the called function, caller pops the arguments off the stack or incre-

ments the stack pointer.

The called function performs the following tasks:

1. If the called function is a monitor function only, push the existing value of the inter-

rupt control register IRQCTL on the stack and disable interrupts.

2. Push the frame pointer onto the stack and allocate the local frame:

a.

Set the frame pointer to the current value of the stack pointer.

b. Decrement the stack pointer by the size of locals and temporaries, if required.

3. Execute the code for the function.

4. If the function returns a scalar value, place it in the return value registers. For func-

tions returning an aggregate, see the

Special Cases

section on page 220.

5. Deallocate the local frame (set the stack pointer to the current value of frame pointer)

and restore the frame pointer from stack.

6. If the called function is a monitor function only, restore the interrupt control register

IRQCTL from the stack.