Download PGI User's Guide

Transcript
Linux86 and Win32 Programming Model
Table A-6: Structure and Union Arguments
Call
Argument
Stack Address
1
8 (%ebp)
word 0, s
12 (%ebp)
word 1, s
16 (%ebp)
...
...
i(1,s);
Implementing a Stack
In general, compilers and programmers must maintain a software stack. Register %esp is the stack
pointer. Register %esp is set by the operating system for the application when the program is started.
The stack must be a grow-down stack.
A separate frame pointer enables calls to routines that change the stack pointer to allocate space on
the stack at run-time (e.g. alloca). Some languages can also return values from a routine allocated on
stack space below the original top-of-stack pointer. Such a routine prevents the calling function from
using %esp-relative addressing to get at values on the stack. If the compiler does not call routines that
leave %esp in an altered state when they return, a frame pointer is not needed and is not used if the
compiler option –Mnoframe is specified.
Although not required, the stack should be kept aligned on 8-byte boundaries so that 8-byte locals are
favorably aligned with respect to performance. PGI's compilers allocate stack space for each routine in
multiples of 8 bytes.
Variable Length Parameter Lists.
Parameter passing in registers can handle a variable number of parameters. The C language uses a
special method to access variable-count parameters. The stdarg.h and varargs.h files define several
functions to access these parameters. A C routine with variable parameters must use the va_start
macro to set up a data structure before the parameters can be used. The va_arg macro must be used to
access the successive parameters.
295