Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: systwo on January 14, 2012, 11:14:12 pm

Title: Set by Address restrictions?
Post 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?

Code: [Select]
ld a, (var1)
ld b, (var1)

The error spasm outputs:
Code: [Select]
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

Code: [Select]
;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.
Title: Re: Set by Address restrictions?
Post by: Hot_Dog on January 14, 2012, 11:59:25 pm
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!
Title: Re: Set by Address restrictions?
Post by: Quigibo on January 15, 2012, 01:34:43 am
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).

Code: [Select]
ld bc,(var1-1)
This works because 2 byte numbers are stored as little endian in memory.
Title: Re: Set by Address restrictions?
Post by: Runer112 on January 15, 2012, 01:39:28 am
I think you mean:

Code: [Select]
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. ;)
Title: Re: Set by Address restrictions?
Post by: Quigibo on January 15, 2012, 02:20:32 am
Oops yeah, you're right, I was thinking of hl.  Fixed.
Title: Re: Set by Address restrictions?
Post by: systwo on January 15, 2012, 02:02:09 pm
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.
Title: Re: Set by Address restrictions?
Post by: Hot_Dog on January 15, 2012, 02:56:21 pm
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).

Code: [Select]
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