|calling conventions for MIPS 2000/3000 email@example.com (1991-08-21)|
|Re: calling conventions for MIPS 2000/3000 firstname.lastname@example.org (1991-08-23)|
|From:||email@example.com (William Chen)|
|Organization:||University of Illinois|
|Date:||Fri, 23 Aug 91 04:00:14 GMT|
> In particular I am confused about the size of the "procedure call
> argument area". I realize that I must allocate space here even though
> arguments are being passed in registers. What I'm baffled about is
> exactly how much space must be allocated here.
> For example, for this simple C function,
> void main()
> float x;
> x = 1.0;
> "cc -O" generates a frame of length 24 bytes. This apparently
> includes 4 unused bytes at the "top" of the frame, 4 bytes for saving
> r31, and 16 bytes for the arguments area. Why 16 bytes here? It looks
> like only 12 bytes are needed, 4 for the char * first parameter and 8
> for x converted to a double. But if only 12 bytes are allocated then
> printf prints garbage.
One reason immediately comes to mind is variable parameter passing. The
callee will assume the maximum number of parameters passed in registers. In
this example, "printf" is a variable parameter function, and MIPS will save
all passing registers ($4, $5, $6, and $7) on the stack first. If the caller
does not allocate 16 bytes, other values on the stack will be overwritten.
Since separate compilation is possible, there is no way for the caller to
predict how much stack space the callee is required, and the full 16 bytes
must be allocated.
In your example, 16 bytes of parameter passing space is needed regardless,
since the 'double' variable is aligned on the 3rd passing parameter ($6,$7,
and register $5 is skipped). Then you have $4, blank, $6, $7 (char * is 4
bytes, 4 bytes of blank space, and 8 bytes for the double).
Also, very *** IMPORTANT *** is that MIPS architecture requires the frame size
to be a multiple of * 8 *. This can explain your example where 24 bytes of
stack space is required (16 bytes for parameter, 4 bytes for the return
address, and 4 bytes for alignment). In your example, I am not exactly sure
what you did, but the garbage value printed out is very possibly caused by the
non-multiple of 8 stack frame.
William Y. Chen | firstname.lastname@example.org
University of Illinois |
Center for Reliable and | (217)333-4171
High-Performance Computing |
Return to the
Search the comp.compilers archives again.