beautypg.com

Chapter 4 run time environment, Function calls, Function call steps – Zilog Z80380 User Manual

Page 65

background image

UM004001-COR1103

4–1

380 C-

COMPILER

U

SER

S

M

ANUAL

C

HAPTER

4

R

UN

T

IME

E

NVIRONMENT

FUNCTION CALLS

The C-compiler imposes a strict set of rules on function calls. Except for special runtime-
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 program to fail.

F

UNCTION

C

ALL

S

TEPS

A function performs the following tasks when it calls another function:

1. The caller saves the registers that are in use.

2. The caller pushes the arguments on the stack in reverse order (the rightmost declared

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

3. The caller calls the function.

4. When the called function is complete, the caller pops the arguments off the stack.