• Keine Ergebnisse gefunden

EPSONParameter file

6.5 Compiler Output

This section explains the assembly sources output by the gcc33 and the registers used by the gcc33.

6.5.1 Output Contents

After compiling C sources, the gcc33 outputs the following contents:

· E0C33000 instruction set mnemonics

· Extended instruction mnemonics

· Assembler pseudo-instructions

All but the basic instructions are output using extended instructions. Therefore, be sure to use the Instruction Extender ext33 to process the assembly source files output by the gcc33. These files cannot be assembled directly by the Assembler as33. Nor can the assembly source files output be put through the Preprocessor pp33.

Since the system control and MAC instructions cannot be expressed in the C source, use in-line assemble by asm or an assembly source file to process them.

Example: asm ("mac %r12")

Assembler instructions are output for section and data definitions. For details about the assembler pseudo-instructions, refer to Section 11.8, "Assembler Pseudo-instructions".

The following describes the sections where instructions and data are set.

Instructions

All instructions are located in the CODE section.

Global and static variables without initial values These variables are located in the BSS section.

Example: int i; .comm i 4 Global and static variables with initial values

These variables are located in the DATA section.

Example: int i=1; .global i .data .align 2 i2:

.word 1 Constants

Constants are located in the CODE section.

Example: const int i=1 .global i

.code .align 2 i2:

.word 1

For all symbols including function names and labels, symbol information by assembler pseudo-instruction .def is inserted (when the -g option is specified). For details about the symbol information, refer to Section 6.6,

"Debugging Information".

Labels are output in the following format:

__Limm31 Jump address label

__LCimm31 Character string constant label __Lbimm31 Beginning of block position label __Leimm31 End of block position label

(imm31 takes on a decimal number in the range of 0 to 2,147,483,647.)

6.5.2 Data Representation

The gcc33 supports all data types under ANSI C. Table 6.5.2.1 below lists the size of each type (in bytes) and the effective range of numeric values that can be expressed in each type.

Table 6.5.2.1 Data type and size Effective range of a number -128 to 127

1.175e-38 to 3.403e+38 (normalized number) 2.225e-308 to 1.798e+308 (normalized number) Size

The float and double types conform to IEEE standard formats.

Store positions in memory

The positions in the memory where data is stored depend on the type. Regardless of whether it is global or local, data is located in the memory in as many bytes as are determined by the size beginning with an address that can be divided by the size.

The double type is aligned at 4-byte boundary addresses, so that the 4 low-order bytes of data (mantissa part (31–0)) are stored in 4 bytes of low-order locations of memory, and the 4 high-order bytes of data (sign, exponent, and mantissa part (51–32)) are stored in 4 bytes of high-order memory locations.

Structure data

Structure data is located in the memory beginning with 4-byte boundaries (addresses divided by 4) in the same way as stated above for the double type. Members are located in the memory according to the size of each data type in the order they are defined.

The following shows an example of how structure is defined, and where it is located.

Example: struct Sample {

char cData;

CHAPTER 6: C COMPILER

EPSON

6.5.3 Method of Using Registers

The following shows how the gcc33 uses general-purpose registers.

Table 6.5.3.1 Method of using general-purpose registers by gcc33 Method of use

Registers that need have to their values saved when calling a function

Scratch registers

Global pointer (unused; used by ext33)

Scratch register for expanding extended instruction (unused; used by ext33)

Register for storing returned values (8/16/32-bit data, 32 low-order bits of double-type data) Register for storing returned values (32 high-order bits of double-type data)

Register for passing argument (1st word) Register for passing argument (2nd word) Register for passing argument (3rd word) Register for passing argument (4th word) Register

Registers for saving values when calling a function (R0 to R3)

These registers are used to store the calculation results of expressions and local variables. These register values after returning from a function must be the same as those when the function was called. Therefore, the called function has to save and restore the register values if it modifies the register contents.

Scratch registers (R4 to R7)

These registers are used to store the temporary calculation results of expressions and local variables. These registers do not need to be saved when calling a function.

Global pointer (R8)

This register is reserved for storing a global pointer. The gcc33 does not use this register.

Scratch register for expanding extended instructions (R9)

Provided for use in assemble, this register is used by the Instruction Extender ext33 as it expands an extended instruction. The gcc33 does not use this register.

Registers for storing returned values (R10, R11)

These registers are used to store returned values. They are used as scratch registers before storing a returned value.

Registers for passing arguments (R12 to R15)

These registers are used to store arguments when calling a function. Arguments exceeding the four words are stored in the stack before being passed. They are used as scratch registers before storing arguments.

Note: When creating assembler subroutines that are called from C routines, pay attention to the register usage.

• The R4 to R7 registers can be used without saving/restoring the contents.

• The R10 and R11 registers can be used without saving/restoring the contents until a returned value is set in the register before returning.

• Before the R12 to R15 registers can be used, the stored arguments must be used or saved in other locations. It is necessary to restore the contents before returning.

• Try to use the R8 and R9 registers as little as possible.

• Before the R0 to R3 registers can be used, the contents must be saved to stack using the pushn instruction. Also, the saved contents must be restored from the stack using the popn instruction.

6.5.4 Function Call

The way arguments are passed

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 (wN: arguments equal to or smaller than word size) Basically, arguments are stored in R12 to R15 in the order that they are specified.

Data size of argument

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

(wN: arguments equal to or smaller than word size; dN: arguments of double type) Handling of structure arguments (Note)

If the argument is structure data, the values of structure members are passed via a stack.

Example: struct _foo {

int a;

short b;

char c;

};

callee(struct _foo foo, int d);

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.

Passing argument to a function that returns structure (Note)

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.

Saving registers

If a called function modifies the R0 to R3 registers, the function has to save and restore the register values.

CHAPTER 6: C COMPILER

EPSON

6.5.5 Stack Frame

When calling a function, the gcc33 creates the stack frame shown in Figure 6.5.5.1. The start address of the stack frame is always a word (32-bit) boundary address.

Return address

Allocated by call instruction, cleared by ret instruction Register save area

R3 (4 registers at maximum) :

First argument stored in the stack

Allocated by function

This is the return address (1 word) to the calling function.

Register save area

If any registers from R0 to R3 are used by the calling function, they are saved to this area in order of register numbers beginning with the highest.

If none of the registers from R0 to R3 is used by the calling function, this area is not allocated.

Local variable area

If there are any local variables defined in the called function that cannot be stored in registers, an area is allocated in the stack frame. Then they are saved sequentially beginning with the last-declared variable at boundary addresses (4-byte boundaries for the double type) according to the data types.

Example: {

Fig. 6.5.5.2 Example of local variables saved to stack This area is not allocated if there is no local variable that needs to be saved in the stack.

Argument area

If there are any arguments for another function call in the called function that cannot be stored in the registers for passing argument, an area is allocated in the stack frame (see the preceding section). All arguments are located at 4-byte boundaries. The 32 low-order double-type bits are saved at low-order addresses, and the 32 high-order bits are saved at the high-order addresses.

This area is not allocated if there is no function call.

Allocating and clearing the stack area

A stack area for the return address is allocated and the address is saved to this area by the call instruction.

The address is popped from the stack and the area is cleared by the ret instruction.

All other areas are allocated in the prologue processing of the function, and are cleared in the epilogue processing.