Instructions
216Compiler
© 2013 Conrad Electronic
done to save bytecodes in the interpreter. Is the assembly routine declared as byte, a word must
be a written as the return value, if the assembly routine is of type char, an int is required. In all other
cases no change is needed.
; return a + c
MOVW R30, R6 ; copy stack pointer from R6
ADIW R30, 4 ; add 4 to sp - ADIW only works for R24 and greater
MOVW R6, R30 ; copy back to stack pointer location
ST Z+, R24 ; store R24, R25 on stack
ST Z, R25
4.4.3 Guideline
The most important topics on how to program in Assembler for C-Control Pro are explained here:
Assembler calls are atomic. An Assembler call cannot be interrupted by Multithreading or an
Bytecode Interruptroutine. This is similar to Library calls. An interrupt is recorded immediately by
the internal interrupt structure, but the corresponding Bytecode interrupt routine is called after the
assembler procedure has been ended.
Do not change the Y Register (R28 and R29), it is used from the interpreter as a data stack
pointer. Assembler interrupt routines use the Y-Register to save register contents and might else
be crash.
The register R0, R1, R22, R23, R24, R25, R26, R27, R30, R31 can be used in Assembler routines
without backup. If other register are used, the contents must be saved first. Normally these values
are stored on the stack. E.g.
at begin: PUSH R5
PUSH R6
...
at end: POP R6
POP R5
An Assembler routine is left with a "RET" instruction. At this point the CPU stack must be in the
same state as before the call. The contents of the register that need to be backuped must be re-
stored.
Debugging only works in the Bytecode Interpreter, it is not possible to debug in Assembler.
The Bytecode Interpreter has a fixed memory layout. In no case use Assembler directives like
.byte, .db, .dw, .dseg or similar. In an access to the data segment this would cause the Assem-
bler to overwrite memory that is used by the Bytecode Interpreter. If global variables are needed,
they should be declared in CompactC and Basic, and then can be accessed like described in the
chapter Data Access.
Do not set the address of an Assembler routine with .org. The IDE generates itself a .org directive
when starting the AVRA Assembler.