Re: LZ: Variable bit?


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

Re: LZ: Variable bit?



On Thu, 17 Jul 1997 Terry Peng <tpeng@geocities.com> writes:

>Help! I can't figure out what's wrong with this routine.
>Ok, let's say I need to access a variable bit in indirect memory.
>I have the variable in register b, except it's not your regular way of 
>>numbering the bits.
>
>		MSBit	      LSBit
>byte:		0 1 0 0 1 1 0 1
>regular way:   7 6 5 4 3 2 1 0
>my way:        1 2 3 4 5 6 7 0
>
>Would something like this work?

It looks to me like it would work.  You can put the "jr z,endrotate"
before the "ld a,(de)" which will make it a little bit faster when
the bit number is 0.  It is not necessary, because the "ld a,(de)"
doesn't change the condition codes.

>;input: b=no. of bit
>;	(de)=byte
>;output: copy the bit to the carry flag
>GetBit:
>	xor	a		;same as ld a,0
>	cp	b		;b is the number of the bit
>	ld	a,(de)		;the byte to test is at (de)
>	jr	z,endrotate	;if b=0, goto endrotate
>rotate:
>	rlca			;get the important bit into bit 0
>	djnz	rotate
>endrotate:
>	srl	a		;copy the LSBit to the carry flag
>	ret

--
Patrick Davidson (ariwsi@juno.com)
Visit my home page!  Stuff for Amiga, TI-85, TI-92, even DOS!
http://www.calweb.com/~kwdavids/patrick/
http://www.toptown.com/hp/ariwsi/


References: