JonB,
You shouldn't be too frightened by stack frames - perhaps now is time to learn something new?!
Let's take this simple 'C' function:
int GB; /* A global */
void fred( int a ) {
int B = 42;
@@@
} /* End of function fred */
You should be able to replace the @@@ with assembler code something like the following (plus whatever top and tail is required by the 'C' compiler) to access the value of B:
LD H,(IX-1) ; Pick up the high-byte of local B.
LD L,(IX-2) ; Pick up the low-byte of local B.
LD _GB,HL ; Store to a global for printout purposes.
within the main function you should be able to:
Set GB to 0 [GB=0;]
Call function fred [fred();]
print out the result [printf("GB=%d.\n",GB);]
The next thing to try is to have another local variable within the function [int C = 43;]
The question then is "does B or C get stored first in the stack frame". Try it and find out.
Once you have found out the answer to this question - you should be able to work out how to access any local variable - given that you know the layout of the stack frame. You should also be able to work out how to access parameters of the function - as they are stored in a similar way (just at positive byte offsets from IX). Again, you need to work out the order that the function parameters are stored in the stack frame.
The use of LD register8,(IX-XX) will work for a small numbers of local variables. You will have to extend this mechanism for access to larger stack frames e.g.:
PUSH IX ; Get IX to DE
POP DE ; "
LD HL,offset16 ; 16 bit offset into stack frame (-ve for locals, +ve for function parameters).
ADD HL,DE ; Index into stack frame.
; HL now points at your local variable or parameter.
Hope this is of some help?
Dave
PS: Apologies for my poor Z80 assembler coding - it is probably 20 years since I last did any Z80 assembler work!