Using Embedded Assembly
Using Embedded Assembly
Embedding Assembly in C
Embedding Assembly in C
Allows direct access to assembly language from C
Allows direct access to assembly language from C
Useful for operating on components not used by C, ex:
Useful for operating on components not used by C, ex:
asm ( “ CLRC INTM ; enable global interrupt” );
asm ( “ CLRC INTM ; enable global interrupt” );
Note: first column after leading quote is
Note: first column after leading quote is
label
label
field
field
-
-
if no label,
if no label,
should be blank space.
should be blank space.
Avoid modifying registers used by C
Avoid modifying registers used by C
Lengthy code should be written in ASM and called from C
Lengthy code should be written in ASM and called from C
main C file retains portability
main C file retains portability
yields more easily maintained structures
yields more easily maintained structures
eliminates risk of interfering with registers in use by C
eliminates risk of interfering with registers in use by C
#define EINT
#define EINT
asm
asm
( “ CLRC INTM”)
( “ CLRC INTM”)
The assembly function allows for C files to contain 28x assembly code. Care should be taken not
to modify registers in use by C, and to consider the label field with the assembly function. Also,
any significant amounts of assembly code should be written in an assembly file and called from
C.
There are two examples in this slide – the first one shows how to embed a single assembly
language instruction into the C code flow. The second example shows how to define a C term that
will invoke the assembly language instruction.
C28x – C Programming D - 7