Re: A86: I need help...
[Prev][Next][Index][Thread]
Re: A86: I need help...
This should work:
call _clrLCD ;clear screen
call _homeup ;0,0 screen coords
ld b, 5 ;initialize your counter to 5
xor a ;xor a is a quick way of setting a=0
ld c, a ;put zero into c
subby_loop:
inc a ;increment line counter
ld (_curRow), a ;set the new line value
ld (_curCol), c ;put zero into column
ld hl, string ;point to start of the text you want to display
call _puts ;display it
djnz subby_loop ;loops [b] times, or, in this case, 5 loops
ret ;return to shell or homescreen
Your problem was that it was looping infinitely. You decremented your b
register each time it looped, but you didn't check its value at the end,
and there was no way to exit the loop. The call to _getkey would wait
for any key to be pressed, and then it would reloop. You don't need to
check keypresses unless you want to, say, see if EXIT or some other key
has been pressed, and leave the loop. A good way to loop for a certain
number of times is the DJNZ instruction. Set the b register to the
number of iterations to perform, and then put djnz at the end of the
loop. It decrements b, and if it is not zero, it jumps to the start of
the loop again. Thus the code above would loop 5 times (until b=0) and
then it would move on to the RET, which exits your program.
Hope that helps.
Cassady Roop
> I am an absolute newbie asm programmer in every way, and I have written a
> simple program so I can try to understand loops... It's supposed to display
> string: five times, but it doesn't really work... Could someone offer any
> advice? Thanks
>
> call _clrLCD ; clears screen
>
> call _homeup ; 0 to curCol and 0 to curRow
> ld b,5 ; puts 5 in b register
> ld a,0
> subby_loop: ; my awesome loop
> dec b ; decrements b
> inc a ; increments a
> ld (_curRow),a ; loads value of b into curRow
> ld (_curCol),0 ; loads value of b into curCol
> ld hl,string ; puts string in hl
> call _puts ; displays string
> call _getkey
> jr nz,subby_loop ; continued until b is zero
> ret ; return to shell or homescreen
> ret
>
> string:
> .db "SHOULD show 5 times",0 ; creates string, terminated with 0
>
> .end
References: