Re: A85: Optimizing...


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

Re: A85: Optimizing...



On Wed, 19 Nov 1997 08:19:54 -0800, you wrote:

>Can anyone tell me the best method (as in smallest # of bytes) to limit
>a number?
>(Like, if I have a number rangeing from 0 to FFh and I want it in the
>range 0 to 39h)
>Here is what I think it is, butI just want to make sure:
>
>    (A holds the value to be limited)
>    cp 39h
>    jr c, PastIt
>    ld A,39h
>PastIt:
>

It may be possible if your code is something like

   ld a,c
   cp 39h
   jr c,PastIT
   ld A,39h
PastIt:
   ld c,a

with the value in c, not a (you load into a only for comparison
reasons).  you could then do something like:

   ld a,39h
   cp c
   jr nc,PastIt
   ld c,a
PastIt:

The code is 8 vs 6 bytes.  Or if speed is not a problem, you could
make it into a subroutine and use a call, which is only 3 bytes.


-mike pearce
mgp4007@omega.uta.edu


References: