Next Previous Contents

13. Inline assembler code.

SDCC allows the use of in-line assembler with a few restriction as regards labels. All labels defined within inline assembler code HAS TO BE of the form nnnnn$ where nnnn is a number less than 100 (which implies a limit of utmost 100 inline assembler labels per function). It is strongly recommended that each assembly instruction (including labels) be placed in a separate line ( as the example shows). When the --peep-asm command line option is used, the inline assembler code will be passed through the peephole optimizer, this might cause some unexpected changes in the inline assembler code, please go throught the peephole optimizer rules defined in file 'SDCCpeeph.def' carefully before using this option.

         mov b,#10 
         djnz b,00001$
_endasm ;

The inline assembler code can contain any valid code understood by the assembler (this includes any assembler directives and comment lines ) . The compiler does not do any validation of the code within the _asm ... _endasm; keyword pair.

Inline assembler code cannot reference any C-Labels however it can reference labels defined by the inline assembler.

egfoo() { 
... /* some c code */ 
     ; some assembler code 
   ljmp $0003 
_endasm ; 
... /* some more c code */ 
clabel:   /* inline
 assembler cannot reference this label */ 
   $0003: ;label (can
 be reference by inline assembler only) 
_endasm ; 

In other words inline assembly code can access labels defined in inline assembly. The same goes the other way, ie. labels defines in inline assembly CANNOT be accessed by C statements.

Next Previous Contents