SC100 C Compiler
4-1
Chapter 4
Interfacing C and Assembly Code
The SC100 C compiler supports interfacing between C source code and assembly code, enabling access to
functionality not provided by C. This chapter describes the features of this interface and provides
instructions, guidelines, and examples.
The following sections are contained in this chapter:
Section 4.1,
“
Inlining a Single Assembly Instruction,
”
explains how to use individual assembly
instructions in your C source code.
Section 4.2,
“
Inlining a Sequence of Assembly Instructions,
”
describes how to embed an assembly
function consisting of a sequence of assembly instructions into your C code.
Section 4.3,
“
Calling an Assembly Function in a Separate File,
”
explains how an assembly function
that is contained in a separate file can be used in conjunction with your C source files.
Section 4.4,
“
Including Offset Labels in the Output File,
”
describes the use of symbolic offsets for
C data structures in the assembly output file.
4.1 Inlining a Single Assembly Instruction
A single assembly instruction can be inlined in a sequence of C statements and compiled by the compiler.
To ensure successful compilation of an inlined assembly instruction, note the following guidelines:
The compiler passes an inlined instruction to the assembly output file in the form of text, and
therefore has no knowledge of the contents or side effects of the instruction. It is important that you
ensure that there is no risk of the instruction affecting the C and/or assembly environment and
producing unpredictable results. For example, you should not use an inlined assembly instruction to
change the contents of registers, as the compiler has no knowledge of such changes. Similarly, you
should not include any jumps or labels which access the C code and may affect the correctness of
the tracking algorithms.
Inlined assembly code instructions are ignored by the optimizer.
Since the compiler treats the assembly instruction as a string of text, it cannot perform any error
checking on the instruction. Check the syntax and text of the instruction carefully prior to
compilation. Errors in assembly code are identified only at the assembly stage of the compilation
process.
A single inlined assembly instruction cannot reference a C object. The only way to reference a
C object in assembly code is by inlining a sequence of assembly instructions, as described in
Section 4.2,
“
Inlining a Sequence of Assembly Instructions.
”