Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: systwo on January 14, 2012, 11:14:12 pm
-
Hello again everyone!
I'm going through Hot Dog's tutorial on asm right now and I have encountered a slight problem. Working with variables, ld doesn't want to set a register. In the snippet below, the first line will work but the second one will not. Is there something I skipped over accidentally?
ld a, (var1)
ld b, (var1)
The error spasm outputs:
Pass one...
learn2.asm:7: warning: Suggest remove extra parentheses around argument
Pass two...
learn2.asm:7: warning: Number is too large to fit in 8 bits, truncating
Done
Here is the code
;Multiplication program
#include "ti83plus.inc"
.org $9d93
.db t2ByteTok, tAsmCmp
B_CALL _ClrLCDFull
ld a, (Mula) ;Holds the answer
ld b, (Mulb) ;How many times to multiply
ld c, a ;What to add every time it multiplies, or else it will do powers
BeginLoop:
add a, c
djnz BeginLoop ;Remember that the b is decresed before it checks
ld h, 0
ld l, a
B_CALL _DispHL
ret
Mula:
.db 5
Mulb:
.db 5
Thanks!
Edit:
Found the answer! For those who look at this in the future, you can only use register a to retrieve data. You need to store the memory address in hl for other registers.
-
You can also get the value in register A, and then use "ld b, a"
Wonderful job on this program so far! Keep up the good work!
-
There is also another cool trick the same size and
speed almost the same speed as Hot_Dog's suggestion but destroys the value of 'c' instead of 'a' (in case you need to preserve a).
ld bc,(var1-1)
This works because 2 byte numbers are stored as little endian in memory.
-
I think you mean:
ld bc,(var1-1) ;c=(var1-1), b=(var1)
And that's the same size as Hot_Dog's suggestion, but it's 3 cycles slower. ;)
-
Oops yeah, you're right, I was thinking of hl. Fixed.
-
Wow! Thanks for the advice, I have yet to reach the multi-byte storage lesson yet, but I'm sure it will make sense to me when I get there.
-
There is also another cool trick the same size and speed almost the same speed as Hot_Dog's suggestion but destroys the value of 'c' instead of 'a' (in case you need to preserve a).
ld bc,(var1-1)
This works because 2 byte numbers are stored as little endian in memory.
That's one of those tricks that totally makes sense but someone like me forgets about ;D