User`s manual

182 digi.com Using Assembly Language
11.4.4 Local Variable Access
Accessing static local variables is simple because the symbol evaluates to the address directly. The follow-
ing code shows, for example, how to load static variable y into HL.
11.4.4.1 Using the IX Register as a Frame Pointer
Using IX as a frame pointer is a convenient way to access stack variables in assembly. Using SP requires
extra bookkeeping when values are pushed on or popped off the stack.
Now, access to stack variables is easier. Consider, for example, how to load ch into register A.
The IX+offset load instruction takes 9 clock cycles and opcode is three bytes. If the program needs to load
a four-byte variable such as lg, the IX+offset instructions are as follows.
This takes a total of 24 cycles.
The offset from IX is a signed 8-bit integer. To use IX+offset, the variable must be within +127 or –128
bytes of the frame reference point. The @SP method is the only method for accessing variables out of this
range. The @SP symbol may be used even if IX is the frame reference pointer.
11.4.4.2 Using Index Registers as Pointers to Aggregate Types
The members of Dynamic C aggregate types (structures and unions) can be accessed from within an
assembly block of code using any of the index registers: IX, IY, SP.
The library pool.lib has code that illustrates using an index register in assembly to access the member
of a structure that was defined in Dynamic C. Refer to the function palloc_fast().
Here is another example:
typedef struct{
int x;
int y;
long time;
}TStruct;
void func(int x, int y, TStruct *s){
#asm
ld ix,(sp+@SP+s)
ld hl,(ix+[TStruct]+y)
.
.
#endasm
}
ld hl,(y) ; load hl with contents of y
ld a,(ix+ch) ; a <-- ch
ld hl,(ix+lg+2) ; load LSB of lg
ld b,h ; longs are normally stored in BC:DE
ld c,L
ld hl,(ix+lg) ; load MSB of lg
ex de,hl