I have a program with two data tables and a result table
ORG $B000
TABLE1 FCB 222, 37, ...
TABLE2 FCB 37, 100, ...
ORG $B010
RESULT RMB 8
My program loops through the values in each table and passes them to a function which finds their greatest common denominator. The returned value is passed over the stack and needs to be stored in the Result table. Here is what I have so far
ORG $C000
LDX #TABLE1
LDY #TABLE2
WHILE LDAA 0,X WHILE (*TABLE1 != -1)
CMPA #$FF
BEQ ENDWHILE
LDAA 0,X PASS VARIABLES TO
LDAB 0,Y SUBROUTINE IN REGISTER
INX TABLE1++
INY TABLE2++
JSR SUB
PULA
STAA RESULT GET RETURN VALUE FROM STACK
The above code is working properly as is my subroutine. I can't figure out how to increment my RESULT variable. I tried using a loop counter as an offset but for some reason the below code stores at location $B019 instead of $B010
STAA COUNTER,RESULT
INC COUNTER
If anything is unclear or if you think the question is bad please comment and I will fix it.
There are several problems with your code. For example, STAA COUNTER,RESULT
is not a valid assembly instruction format for 68HC11.
To store the answer in a table, you need a third index. Since 68HC11 has only X and Y for indexing, you need to use an additional variable to keep the extra index. If your table addresses are constants (fixed addresses) in the zero page range (0 to 255) you can even use a single register to access all tables. For example:
LDX #0
LDA TABLE1,x
LDB TABLE2,x
...
JSR SUB
STA RESULT,x
INX
...
Before I can provide a complete answer I'd like to see the SUB subroutine. For SUB to return something on the stack without first having allocated the needed space for it on the stack, it has to do some 'acrobatics' with the stack -- possible but not the normal way to handle this kind of problem.
The normal way would be to create the needed stack space for the returned result before calling SUB, and then SUB would write the answer into that reserved space. In this particular case, however, and unless it's required to be otherwise for academic purposes, it's simpler to just return the result in register A instead of allocating a single byte on stack, and have SUB write to it.
Finally, a PULA after calling SUB is destroying the stack balance as you pull without having pushed before (unless you do 'acrobatics' in SUB, which I haven't seen yet.)
Please provide additional information, and I will update my answer.