Instructions

214Compiler
© 2013 Conrad Electronic
CLR R30 ; the high byte is zero
ST X,R30
ret
.endif
In the second part of the assembler sources the passed parameters "a" and "c" are added as in-
tegers, and then the sum is returned.
.ifdef tag2
proc2:
; example for accessing and returning parameter
; we have int proc2(int a, float b, byte c);
; return a + c
MOVW R30, R10 ; move parameter stack pointer into Z
LDD R24, Z+5 ; load parameter "a" into R24,25
LDD R25, Z+6
LDD R26, Z+0 ; load byte parameter "c" into X (R26)
CLR R27 ; hi byte zero because parameter is byte
ADD R24, R26 ; add X to R24,25
ADC R25, R27
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,25 on stack
ST Z, R25
ret
.endif
4.4.2 Data Access
Global Variables
In the Bytecode Interpreter in the register R8 and R9 lies the 16-Bit pointer to the end of the global
variable memory. If a global variable that is defined in the ".def" file should be accessed, the address
of the variable can be calculated when the variable position is subtracted from the R8, R9 16-Bit
pointer. This looks like:
; global variable access example
; write 0042 to global variable glob1
MOVW R26,R8 ; get Ram Top from register 8,9
SUBI R26,LOW(glob1) ; subtract index from glob1 to get address
SBCI R27,HIGH(glob1)