Return Values - Altera Nios II User Manual

Hide thumbs Also See for Nios II:
Table of Contents

Advertisement

Chapter 7: Application Binary Interface
Arguments and Return Values
Arguments
The first 16 bytes to a function are passed in registers r4 through r7. The arguments
are passed as if a structure containing the types of the arguments were constructed,
and the first 16 bytes of the structure are located in r4 through r7.
A simple example:
int function (int a, int b);
The equivalent structure representing the arguments is:
struct { int a; int b; };
The first 16 bytes of the struct are assigned to r4 through r7. Therefore r4 is assigned
the value of a and r5 the value of b.
The first 16 bytes to a function taking variable arguments are passed the same way as
a function not taking variable arguments. The called function must clean up the stack
as necessary to support the variable arguments. Refer to
with Variable Arguments" on page

Return Values

Return values of types up to 8 bytes are returned in r2 and r3. For return values
greater than 8 bytes, the caller must allocate memory for the result and must pass the
address of the result memory as a hidden zero argument.
The hidden zero argument is best explained through an example.
Example 7–2. Returned struct
/* b() computes a structure-type result and returns it */
STRUCT b(int i, int j)
{
}
void a(...)
{
}
In
Example
and r3.
February 2014 Altera Corporation
...
return result;
...
value = b(i, j);
7–2, if the result type is no larger than 8 bytes, b() returns its result in r2
"Stack Frame for a Function
7–4.
Nios II Processor Reference Handbook
7–7

Advertisement

Table of Contents
loading

Table of Contents