Let's consider this piece of code, that appears in Lesson 3:
Code: Select all
org &8000
ld a, (&9000)
ld bc, (&9001)
cp 0
jr z, MathAdd
cp 1
jr z, MathSub
ld a, 0
SaveResult:
ld a, (&9003)
ret
MathSub:
ld a, c
sub b
jr SaveResult
MathAdd:
ld a,c
add b
jr SaveResult
Code: Select all
SaveResult:
ld a, (&9003)
ret
MathSub:
ld a, c
sub b
jr SaveResult
1) Loads C into A registry.
2) Substracts B from A and stores the result in A.
3) Jumps to SAVERESULT
4) Loads A into &9003
We have:
A = Value of A - B
B = Value of B
C = Value of C
&9003=Value of A
Essentially, A and &9003 have the same value.
Now, lets consider this other code, with a small change:
Code: Select all
SaveResult:
ret
MathSub:
ld a, c
sub b
jr SaveResult
According to my understanding, this should:
1) load C into A
2) Substract B from A and store the result in A.
3) Jump to SAVERESULT
4) Return to BASIC.
In this case we have:
A=Value of B - A
B=Value of B
C=Value of C
If I PEEK &9003 using the first code, I get the addition of A+B
But if I peek &9000 (address of A) I do not get the value of the result B - A.
What I am missing here?
Thanks beforehand.
But in the second case, if I PEEK the address of A, I don't get the addition of A + B, as I was expecting.