This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
Exfyre


Newbie


Joined: 10 Jun 2009
Posts: 8

Posted: 21 Jun 2009 10:46:36 am    Post subject:


Code:
#include "ti83plus.inc"
#define   bcall(label)   RST 28h \ .dw label

   .org    $9D93
   .db     $BB,$6D

start:
   b_call(_ClrLCDFull)
   b_call(_HomeUp)
   ld hl, text1
   push hl
   ld a,0
   ld b,10
loop1:
   pop hl
   b_call(_PutS)
   push hl
   dec b
   cp b
   jr z,loop1
   ret
text1:
.db "*              *"
.db "*              *"
.db "*              *"

.end
END



I want this to loop through loop1 label ten times, but instead, it loops through the whole program an infinite number of times. What have I done wrong?
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 21 Jun 2009 11:25:52 am    Post subject:


Code:
loop1:
   pop hl
   b_call(_PutS)
   push hl
   dec b
   cp b
   jr z,loop1
   ret


You want it to not jump back when the B register is zero, which means you want it to jump when the B register is not zero. If you change "jr z, loop1" to "jr nz, loop1" this should fix your problem.

There are a couple other things that could be changed/simplified:
1) "dec B" will affect the flags, so you don't need the "cp B". This also means you can eliminate the "ld A, 0" part since it's only there for the compare with B.
2) There's an instruction "djnz label" ("djnz" stands for Decrement and Jump if Not Zero) that will decrease B and, if B is not zero, jump to "label". This is essentially equivalent to:

Code:
   dec B
   jp nz, label
.
Back to top
Exfyre


Newbie


Joined: 10 Jun 2009
Posts: 8

Posted: 21 Jun 2009 11:52:56 am    Post subject:

Ok, I changed the code to this:

Code:
#include "ti83plus.inc"
#define   bcall(label)   RST 28h \ .dw label

   .org    $9D93
   .db     $BB,$6D

start:
   b_call(_ClrLCDFull)
   b_call(_HomeUp)
   ld hl, text1
   push hl
   ld a,0
   ld b,10
loop1:
   pop hl
   b_call(_PutS)
   push hl
   djnz loop1
   ret
text1:
.db "*              *"
.db "*              *"
.db "*              *"

.end
END


However, the calculator still loops infinitely through the whole program.





EDIT:
I found out what the problem was. I'd had pops and pushes in the wrong places. I'm guessing _PutS destroyed register b? (lemme know if I'm wrong)
fixed code:

Code:
#include "ti83plus.inc"
#define   bcall(label)   RST 28h \ .dw label

   .org    $9D93
   .db     $BB,$6D

start:
   b_call(_ClrLCDFull)
   b_call(_HomeUp)
   ld hl, text1
   ld b,10
loop1:
   push bc
   push hl
   b_call(_PutS)
   pop hl
   pop bc
   djnz loop1
   ret
text1:
.db "*              *"

.end
END


Last edited by Guest on 21 Jun 2009 12:09:09 pm; edited 1 time in total
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 21 Jun 2009 12:29:54 pm    Post subject:

[s]I don't think that _PutS modifies B (my list of routines says it only modifies HL), but if that fixes the problem, then that's probably the problem.[/s]

[edit] Your problem is the string you're using. _PutS need a zero-terminated string, so you'll need

Code:
  .db "*      *", 0

to be your string. Othewise, _PutS will print characters until it eventually runs into a 00 (which could be pretty much anywhere).


Last edited by Guest on 21 Jun 2009 12:32:17 pm; edited 1 time in total
Back to top
Exfyre


Newbie


Joined: 10 Jun 2009
Posts: 8

Posted: 21 Jun 2009 12:31:35 pm    Post subject:

then hl must have been the problem, because in the original code i popped HL before the PutS and pushed it after, saving the altered version..
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 23 Jun 2009 12:33:56 pm    Post subject:

Null terminated string error and I think PutS destroys B, so yes, you have to save it.


exfyre wrote:
then hl must have been the problem, because in the original code i popped HL before the PutS and pushed it after, saving the altered version..


I don't quite understand what you're trying to say. Best to push hl at the start of the loop and pop it before re-looping. It might be even faster to just do "ld hl,text1" instead of a push\pop.


Last edited by Guest on 23 Jun 2009 12:36:26 pm; edited 1 time in total
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 23 Jun 2009 03:20:18 pm    Post subject:

cjgone wrote:
Null terminated string error and I think PutS destroys B, so yes, you have to save it.

PutS doesn't destroy B.


Code:
   ld   B, 8
_testLoop:
   ld   HL, text
   b_call(_PutS)
   djnz   _testLoop
   ret

text:
   .db   "H", $00

works fine.
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 24 Jun 2009 01:33:12 pm    Post subject:

Yea my bad. I forgot what PuTs destroys.
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement