CSC448: Code Generation: Run-Time Environment VI [59/133] |
Procedures and functions communicate by passing arguments and return values.
There are several calling conventions in common use on x86, but we will use the following convention:
eax
. There are other general purpose
registers: ebx
, ecx
,
edx
.
For example, f(1,2,3)
might compile to:
pushl $3 pushl $2 pushl $1 call f addl $12, %esp
Note that the activation record of the caller grows temporarily before the call (as arguments are pushed onto the stack), and shrinks after the call (when the stack pointer is moved upwards).
The arguments are reversed to allow procedures or functions with a variable number of arguments.