Instructions

215 C-Control Pro IDE
© 2013 Conrad Electronic
When the address of the global variable is in the X register pair (R26,R27), the desired value (in our
example 42) can be written there:
LDI R30,LOW(42)
ST X+,R30
CLR R30 ; the high byte of 42 is zero
ST X,R30
Parameter Passing
Parameters are passed on the stack of the Bytecode Interpreter. The stackpointer (SP) lies in the
register pair R10,R11. Are parameters passed, they are written one after another onto the stack.
Since the stack grows to the bottom, in our example (integer a, floating point b, byte c) the memory
layout looks like this:
SP+5: a (type integer, length 2)
SP+1: b (type float, length 4)
SP+0: c (type byte, length 1)
If the variables a and c should be accessed, a will be found at SP+5 and c at SP. In the following
Assembler code the stack pointer SP (R10,R11) will be copied in the register pair Z (R30,R31), and
the parameters a and c are loaded indirect via Z.
; example for accessing and returning parameter
; we have int proc2(int a, float b, byte 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
The parameter a and c are now in the register pairs X and R24, R25. Now they can be added:
ADD R24, R26 ; add X to R24, R25
ADC R25, R27
Return Parameters
In the routine proc2 the sum is returned. Return parameters are written on the Parameter Stack
(PSP) of the Bytecode Interpreter. The pointer to the PSP lies in the register pair R6,R7. To return a
parameter the PSP pointer must be increased by 4 before the parameter can be written. In opposite
to the normal parameter passing the type of the return parameter is not important. All parameter on
the Parameter Stack have the same length of 4 bytes.
Even with a declared 8-bit return value, the interpreter expects always a 16-bit value. This is