Author Topic: Set by Address restrictions?  (Read 8678 times)

0 Members and 1 Guest are viewing this topic.

Offline systwo

  • LV2 Member (Next: 40)
  • **
  • Posts: 25
  • Rating: +7/-0
    • View Profile
Set by Address restrictions?
« 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.
« Last Edit: January 14, 2012, 11:51:09 pm by systwo »

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Set by Address restrictions?
« Reply #1 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!

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Set by Address restrictions?
« Reply #2 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.
« Last Edit: January 15, 2012, 02:20:27 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Set by Address restrictions?
« Reply #3 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. ;)

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Set by Address restrictions?
« Reply #4 on: January 15, 2012, 02:20:32 am »
Oops yeah, you're right, I was thinking of hl.  Fixed.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline systwo

  • LV2 Member (Next: 40)
  • **
  • Posts: 25
  • Rating: +7/-0
    • View Profile
Re: Set by Address restrictions?
« Reply #5 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.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Set by Address restrictions?
« Reply #6 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