3.67 Caller and Callee
★★
For this exercise, we will examine the code generated by GCC for functions that have structures as arguments and return values, and from this see how these language features are typically implemented.
The following C code has a function process
having structures as argument and return values, and a function eval
that calls process
:
GCC generates the following code for these two functions:
and:
A. We can see on line 2 of function eval
that it allocates 104 bytes on the stack. Diagram the stack frame for eval
, showing the values that it stores on the stack prior to calling process
.
B. What value does eval
pass in its call to process
?
%rsp+64
C. How does the code for process
access the elements of structure argument s
?
%rsp+offset
D. How does the code for process
set the fields of result structure r
?
process
get %rsp+64 as parameter from eval
, and stores data here for eval
.
E. Complete your diagram of the stack frame for eval
, showing how eval
accesses the elements of structure r
following the return from process
.
F. What general principles can you discern about how structure values are passed as function arguments and how they are returned as function results?
Caller allocats space in stack and pass the address to callee, callee stores data in the space and return the address to caller.
Last updated
Was this helpful?