[A83] Re: cant get code to work


[Prev][Next][Index][Thread]

[A83] Re: cant get code to work




> In a message dated 05/10/2002 8:26:19 PM Eastern Daylight Time,
> joe@joepnet.com writes:
>
>
> > Just in my opinion - It's bad coding to pop more words of the stack than
> > you've pushed, especially within subroutines.  Try to think of a way you
> > don't have to do that.  What is the 'inc b' for, BTW?
> > - - Joe
> >
> b is used in the loop which calls this routine.  'djnz' is used to loop it
so
> when 2nd is pressed in the code I posted, the loop goes through one more
> time.  I push and pop bc for that use...  would it be better to use a user
> defined variable?  I don't know of another way to not push/pop bc, and on
an
> earlier post, I was informed that to use the stack in a subroutine, I had
to
> pop/push the memory address (hl).
>
>
Well, since you do not modify b anywhere inside the getkey_2nd except for
after the conditional with the inc b, you do not have to push bc when you
call getkey_2nd and pop it when you return.  All you have to do is this:


> getkey_2nd:
>       ld   a,kReset
>     out  (1),A
>     ld   a,Group7
>     out  (1),A
>     in   a,(1)
>     cp k2nd
>     ret nz
>     inc b
>     ld hl,(friction)
>     inc hl
>     inc hl
>     inc hl
>     ld (friction),hl
>     ret

Just make sure that you do not push bc when you call getkey_2nd and pop it
when you return because doing so will overwrite the inc b.
- -Joe




References: