s5u1c33000c Epson Electronics America, Inc., s5u1c33000c Datasheet - Page 102

no-image

s5u1c33000c

Manufacturer Part Number
s5u1c33000c
Description
Cmos 32-bit Single Chip Microcomputer S5u1c33000c Manual
Manufacturer
Epson Electronics America, Inc.
Datasheet
CHAPTER 6: C COMPILER
6.5.4 Function Call
The way arguments are passed
Data size of argument
Handling of structure arguments
Passing argument to a function that returns structure
Saving registers
Returned values
Note: When a source program in which a structure is passed to or returned from a subroutine, the
86
When calling a function, arguments up to four words are stored in registers for passing argument (R12 to
R15) while larger arguments are stored in the stack frame of the calling function (explained in the next
section) before they are passed.
Example: func(w1, w2, w3, w4, w5, w6); ...w1 R12, w2 R13, w3 R14, w4 R15, w5&w6 Stack
Basically, arguments are stored in R12 to R15 in the order that they are specified.
Arguments in data size of 4 bytes or less are handled in units of words (4 bytes) irrespective of the data
type. The char and short types of data are sign-extended; the unsigned char and unsigned short types are
zero-extended. Only the double type is handled in units of 8 bytes. Unless two registers among R12 to R15
are available when passing an argument of the double type, it is passed via the stack.
Example: func(w1, d2, d3, w4); ...w1 R12, d2(L) R13, d2(H) R14, w4 R15, d3 Stack
If the argument is structure data, the values of structure members are passed via a stack.
Example: struct _foo {
In the above example, only d is stored in the register for passing argument (R12) and all the members of foo
are stored in the stack.
When calling a function that returns structure data, the structure address where the result is stored is set in
the R12 register as the first argument before being passed to the called function. Consequently, the
arguments written in the source are successively carried down by one.
If the structure is not used as a returned value, the compiler assigns dummy structure data to the local
variable area of the calling function and passes the address of this location.
The called function returns the pointer passed in the first argument to the calling function as a return value.
If a called function modifies the R0 to R3 registers, the function has to save and restore the register values.
The R4 to R7 and R10 to R15 registers can be used without such a restriction.
The R8 and R9 can also be used freely, if it does not conflict with the processing of Instruction Extender
ext33.
The word size or less of returned value is stored in the R10 register.
The double-word size (double) of returned value is stored in the R10 (low-order word) and R11 (high-order
word) registers.
actual code is created so that all the members of the structure are copied using the memcpy
function. This is undesirable since it increases the code size, lowers the execution speed and
causes bugs in the compiler. Therefore, pointers should be used for passing structures as much
as possible.
};
callee(struct _foo foo, int d);
int
short
char
(wN: arguments equal to or smaller than word size; dN: arguments of double type)
a;
b;
c;
(Note)
EPSON
(wN: arguments equal to or smaller than word size)
(C COMPILER PACKAGE FOR S1C33 FAMILY) (Ver. 4)
(Note)
S5U1C33000C MANUAL

Related parts for s5u1c33000c