Function Return Values. STMicroelectronics PGI
Anúncio
Anúncio
Win64 Programming Model
%rsp
The stack pointer holds the limit of the current stack frame, which is the address of the stack’s bottommost, valid word. The stack pointer should point to a 16-byte aligned area unless in the prolog or a leaf function.
%rbp
The frame pointer, if used, can provide a way to reference the previous frames on the stack. Details are implementation dependent. A function must preserve this register value for its caller.
MXCSR
The flags register MXCSR contains the system flags, such as the direction flag and the carry flag. The six status flags (MXCSR[0:5]) are volatile; the remainder of the register is nonvolatile.
x87 - Floating Point Control Word (FPCSR)
The control word contains the floating-point flags, such as the rounding mode and exception masking.
This register is initialized at process initialization time and its value must be preserved.
Signals can interrupt processes. Functions called during signal handling have no unusual restriction on their use of registers. Moreover, if a signal handling function returns, the process resumes its original execution path with registers restored to their original values. Thus, programs and compilers may freely use all registers without danger of signal handlers changing their values.
Function Return Values
Functions Returning Scalars or No Value
• A function that returns an integral or pointer value that fits in 64 bits places its result in %rax.
• A function that returns a floating point value that fits in the XMM registers returns this value in %xmm0.
• A function that returns a value in memory via the stack places the address of this memory (passed to the function as a "hidden" first argument in %rcx) in %rax.
• Functions that return no value (also called procedures or void functions) put no particular value in any register.
• A call instruction pushes the address of the next instruction (the return address) onto the stack. The return instruction pops the address off the stack and effectively continues execution at the next instruction after the call instruction. A function that returns a scalar or no value must preserve the caller's registers as previously described. Further, the called function must remove the return address from the stack, leaving the stack pointer (%rsp) with the value it had before the call instruction was executed.
Functions Returning Structures or Unions
A function can use either registers or the stack to return a structure or union. The size and type of the structure or union determine how it is returned. A structure or union is returned in memory if it is larger than
8 bytes or if its size is 3, 5, 6, or 7 bytes. A structure or union is returned in %rax if its size is 1, 2, 4, or 8 bytes.
If a structure or union is to be returned in memory, the caller provides space for the return value and passes its address to the function as a "hidden" first argument in %rcx. This address will also be returned in %rax.
374
Download
Anúncio