LZ: Variable bit?


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

LZ: Variable bit?



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?

;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



Thanks,

-- 
Terry Peng
email-  tpeng@geocities.com
web-    http://www.geocities.com/SiliconValley/Bay/5104/index.html


Follow-Ups: