Arguments; Return Values - Intel NIOS II Owner Reference Manual

Table of Contents

Advertisement

7. Application Binary Interface
NII-PRG | 2018.04.18

7.5.1. Arguments

The first 16 bytes to a function are passed in registers
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
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
assigned the value of a and
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 Stack Frame for a Function with Variable Arguments
Related Information
Stack Frame for a Function with Variable Arguments

7.5.2. Return Values

Return values of types up to 8 bytes are returned in
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 5. Returned struct
/* b() computes a structure-type result and returns it */
STRUCT b(int i, int j)
{
...
return result;
}
void a(...)
{
...
value = b(i, j);
}
In the example above, if the result type is no larger than 8 bytes,
result in
If the return type is larger than 8 bytes, the Nios II C/C++ compiler treats this
program as if
Nios II C/C++ compiler sees the code in the Returned Struct example above.
struct
the value of b.
r5
and
.
r2
r3
had passed a pointer to
a()
r4
through
r4
are assigned to
through
r4
on page 150
and
r2
. The example below shows how the
b()
through
. The arguments
r7
.
r7
. Therefore
is
r7
r4
. For return values
r3
returns its
b()
Nios II Processor Reference Guide
153

Advertisement

Table of Contents
loading

Table of Contents