Example 2. Assembly Language Program Called by Example 1

.global asmfunc .global gvar asmfunc: LDW *+b14(gvar),A3 NOP 4 ADD a3,a4,a3 STW a3,*b14(gvar) MV a3,a4 B b3 NOP 5

In the C++ program in Example 1, the extern declaration of asmfunc is optional because the return type is int. Like C/C++ functions, you need to declare assembly functions only if they return noninteger values or pass noninteger parameters.

NOTE

SP Semantics

The stack pointer must always be 8-byte aligned. This is automatically performed by the C compiler and system initialization code in the run-time-support libraries. Any hand-written assembly code that has interrupts enabled or calls a function defined in C or linear assembly source should also reserve a multiple of 8 bytes on the stack.

NOTE

Stack Allocation

Even though the compiler guarantees a doubleword alignment of the stack and the stack pointer (SP) points to the next free location in the stack space, there is only enough guaranteed room to store one 32-bit word at that location. The called function must allocate space to store the doubleword.

NOTE

Alignment of __x128_t Type Data Objects (C6600 Only)

The C6600 provides the 128-bit container type __x128_t. Global data objects of this type are aligned to an 16-byte boundary (128 bits). Local __x128_t variables are allocated on the stack, but are not necessarily aligned on an 16-byte boundary, since their actual alignment depends on the alignment of the stack pointer (SP) and the SP-relative offset of the local __x128_t type object. The compiler aligns the stack to an 8-byte boundary.