SDCC allows the use of in-line assembler with a few restrictions regarding labels. All labels defined within inline assembler code have to be of the form nnnnn$ where nnnnn is a number less than 100 (which implies a limit of utmost 100 inline assembler labels per function).typeset@protect @@footnote SF@gobble@opt This is a slightly more stringent rule than absolutely necessary, but stays always on the safe side. Labels in the form of nnnnn$ are local labels in the assembler, locality of which is confined within two labels of the standard form. The compiler uses the same form for labels within a function (but starting from nnnnn=00100); and places always a standard label at the beginning of a function, thus limiting the locality of labels within the scope of the function. So, if the inline assembler part would be embedded into C-code, an improperly placed non-local label in the assembler would break up the reference space for labels created by the compiler for the C-code, leading to an assembling error.
The numeric part of local labels does not need to have 5 digits (although this is the form of labels output by the compiler), any valid integer will do. Please refer to the assemblers documentation for further details.
__asmInline assembler code cannot reference any C-labels, however it can reference labels defined by the inline assembler, e.g.:
mov b,#10
00001$:
djnz b,00001$
__endasm ;
foo() {In other words inline assembly code can access labels defined in inline assembly within the scope of the function. The same goes the other way, i.e. labels defines in inline assembly can not be accessed by C statements.
/* some c code */
__asm
; some assembler code
ljmp 0003$
__endasm;
/* some more c code */
clabel: /* inline assembler cannot reference this label */ typeset@protect @@footnote SF@gobble@opt Here, the C-label clabel is translated by the compiler into a local label, so the locality of labels within the function is not broken.
__asm
0003$: ;label (can be referenced by inline assembler only)
__endasm ;
/* some more c code */
}