Section 2: Compiler
79
TI
-
89 / TI
-
92 Plus Sierra C Assembler Reference Manual
Not for Distribution
Beta Version February 2, 2001
call. If the link instruction is used, the movem instruction moves the registers to
be saved into stack space reserved by the link. If the link is not used, the
movem instruction pushes the registers to be saved onto the stack. A second
movem instruction restores the saved registers before the function returns.
When the link instruction is present, the function parameters are referenced
relative to the frame pointer — register a6. The offset from register a6 required to
reference the leftmost function parameter (i.e., the last parameter pushed onto
the stack) is eight bytes: four bytes for the function return address and four bytes
introduced by the link instruction.
When the link instruction is not present, the function parameters are referenced
relative to the stack pointer — register a7 (also referred to as sp). The offset
from register a7 required to reference the leftmost function parameter is
determined as follows:
•
Four bytes for the function return address.
•
Four bytes for each data or address register pushed onto the stack.
•
Ten bytes for each floating-point register pushed onto the stack.
•
Four bytes introduced by the addq.l #4, sp instruction, if present.
2.11.4. Returning
Values
Functions that return scalar (nonaggregate) data types return their data in one of
several registers. Integer data types are returned in register d0. Address pointers
are returned in register a0 (d0 when the
-XA
flag is specified). Floating-point
data types are returned in register fp0. The type of the return register is
determined by the data type specified in the function declaration.
Functions that return a structure are significantly more complicated than
functions that return a scalar data type. Inside the called function, the structure to
be returned is copied into stack space that is allocated by the calling function.
Information about the reserved stack space is passed to the called function as an
address pointer that is pushed onto the stack immediately before the function call
(as if it were the function’s leftmost argument). Immediately before the function
returns, the structure is copied into the reserved space. The address of the
reserved space is returned in register a0. Immediately after the function returns,
the pointer in a0 is used to copy the returned structure to its destination.