[A83] Re: Question(bit checking)


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

[A83] Re: Question(bit checking)



The only thing about that is it uses non-standard numbering for the bits, 
going from 1 (the right-most bit) to 8 (the left-most) rather than 0 to 7.  
However, as long as you document this, that should work well enough.  It 
should be noted, however, that speed fluctuates rather significantly 
(proportional to the total execution time) based on which bit you're using.  
Consider the following constant-speed alternative:

 ;hl -> byte
 ;a = bit # to check, 0-7
 ;z flag indicates whether bit is 0 or 1

BitCheck:
 rlca      ;4
 rlca      ;4
 rlca      ;4
 or %01000110   ;7
 ld ($+3),a    ;13
 bit 0,(hl)       ;12
 ret              ;10

Total: 54 t-states.


In a message dated 7/7/2001 8:32:53 AM Eastern Daylight Time, 
tijlc@hotmail.com writes:


> Another option might be this:
> 
> ; input: hl->number to check; b=bit to check
> ; output: nz if flag is set
> 
> BitFinder:
>      ld   a,%10000000
> BitFinderLoop:
>      rlca
>      djnz BitFinderLoop
>      and  (hl)
>      ret
> 



----
Jonah Cohen
<ComAsYuAre@aol.com>
http://jonah.ticalc.org




Follow-Ups: