17.05.2015 Views

TMS34010 C Compiler - Al Kossow's Bitsavers

TMS34010 C Compiler - Al Kossow's Bitsavers

TMS34010 C Compiler - Al Kossow's Bitsavers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Runtime Environment - Interfacing C with Assembly Language<br />

5.4 Interfacing C with Assembly Language<br />

There are three ways to use assembly language in conjunction with C code:<br />

• Use separate modules of assembled code and link them with compiled<br />

C modules (see Section 5.4.1). This is the most versatile method.<br />

• Use in line assembly language, imbedded directly in th~ C source (see<br />

Section 5.4.2).<br />

• Modify the assembly language code that the compiler produces (see<br />

Section 5.4.3).<br />

5.4.1 Assembly Langua"ge Modules<br />

Interfacing with assembly language functions is straightforward if you follow<br />

the calling conventions defined in Section 5.3 and the register conventions<br />

defined in Section 5.2. C code can access variables and call functions that<br />

are defined in assembly language, and assembly code can access C variables<br />

and call C functions.<br />

Follow these guidelines to interface assembly language and C:<br />

1 ) <strong>Al</strong>l functions, whether they are written in C or assembly language, must<br />

follow the conventions outlined in Section 5.3 (page 5-8).<br />

2) You must preserve any registers that are modified by a function, except<br />

register A8. When returning from a function, FS1 must equal 32.<br />

3) Interrupt routines must save all the registers they use. (For more information<br />

about interrupt handling, see Section 5.5, page 5-16.)<br />

4) If the caller passes arguments or if the called function returns a float or<br />

a double, save the program stack pointer (A14) by pushing it on the<br />

system stack, then push any arguments on the program stack in reverse<br />

order.<br />

5) Functions must return values correctly according to their C declarations.<br />

Integers and pointers are returned in register A8. <strong>Al</strong>l floating-point values<br />

are returned on the stack. Section 5.3.5 discusses returning structures.<br />

6) No assembly language module should use the .cinit section for any<br />

purpose other than autoinitialization of global variables. The C boot<br />

routine (boot. c) assumes that the .cinit section consists entirely of<br />

initialization tables. Disrupting the tables by putting other information<br />

in .cinit can cause unpredictable results.<br />

7) The compiler prefixes all identifiers with an underscore (_). This means<br />

that you must prefix the name of all objects that are to be accessible from<br />

C with - when writing assembly language. For example, a C object<br />

called x is called -x in assembly. For identifiers that are to be used only<br />

in an assembly language module or modules, any name that does not<br />

begin with a leading underscore may be safely used without conflicting<br />

with a C identifier.<br />

8) Any object or function declared by an assembly language routine that is<br />

to be accessed or called from C must be declared with the .global as-<br />

5-12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!