Instructions
213 C-Control Pro IDE
© 2013 Conrad Electronic
// CompactC Source
void proc1 $asm("tag1")(void);
int proc2 $asm("tag2")(int a, float b, byte c);
int glob1;
void main(void)
{
int a;
proc1();
a= proc2(11, 2.71, 33);
}
The procedures proc1 and proc2 must first be declared, before they can be called. This happens with
the keyword $asm. The declaration in Basic looks similar:
' Basic delaration of assembler routines
$Asm("tag1") proc1()
$Asm("tag2") proc2(a As Integer, b As Single, c As Byte) As Integer
The strings "tag1" and "tag" are visible in the declaration. These strings are defined in a ".def" file, if
the Assembler routines are really called from the CompactC and Basic source. In this case the
".def" file looks like:´
; .def file
.equ glob1 = 2
.define tag1 1
.define tag2 1
When all the routines in the Assembler sources are placed in ".ifdef ..." directions, only the routines
are assembled that are really called. This saves space at the code generation. Additionally the posi-
tion of the global variables are stored in the definition file. The ".def" file is automatically included in
the translation of the assembler files, it needed not to be manually included.
Here follows the assembler source of procedure proc1. In this source the global variable glob1 is set
to the value 42.
; Assembler Source
.ifdef tag1
proc1:
; global variable access example
; write 42 to global variable glob1
MOVW R26,R8 ; get RamTop from register 8,9
SUBI R26,LOW(glob1) ; subtract index from glob1 to get address
SBCI R27,HIGH(glob1)
LDI R30,LOW(42)
ST X+,R30