101 of 172
ZBasic Language Reference 94 ZX Microcontroller Family Program Element Prefixes Element Prefix variable zv_ structure zs_ structure member zm_ subroutine or function zf_ parameter zp_ function return value zr_ For elements that are private to a module, the prefixes given in the table above are augmented by adding an initial letter m. This prevents name conflicts with public elements defined in other modules. Accessing ZBasic program elements in inline assembly code is possible but is more complicated partly due to issues regarding the register allocation, code generation and optimization stragegies employed by the compiler that translates the generated C code to native object code, discussion of which is beyond the scope of this document. That said, here is a simple example using inline assembly code. Dim b as Byte #c char ch; #endc Sub Main() b = 5 #asm ; save the registers used push r30 push r31 push r24 ; load the address of the variable ldi r30, lo8(zv_b) ldi r31, hi8(zv_b) ; load the variable's value and sa ve it ld r24, Z sts ch, r24 ; restore the registers used pop r24 pop r31 pop r30 #endasm End Sub It is important to note that inline assembly code must avoid altering certain registers that the compiler expects to remain unchanged. (The same is true, of course, of any assembly language code.) The code in the example above saves registers that it uses on the stack before using them and then restores their values afterward. There is a mechanism to inform the compiler as to which registers are altered in the inline assembly code thus allowing the compiler to automatically perform the save/restore if necessary. Discussion of that mechanism is an advanced topic that is beyond the scope of this document.