Page 1 of 1

Problems understanding bit logic

Posted: Sat Nov 17, 2018 3:31 am
by pwnskar
Hey guys and gals!

Is there any way on the 6502 that you can check if all bits in the accumulator are set to 1 in a specific order in just one operation?
I thought AND would do the trick but I can only check if ANY of the bits are set that way.

This branches with AND:

Code: Select all

lda #%1000
and #%1100
bne :+
I would like it to branch only if BOTH bit 2 and 3 in a are set, as in %1100, %1110 or %1101. Is there any way I can do this or do I have to AND each bit separately?

Cheers!

Re: Problems understanding bit logic

Posted: Sat Nov 17, 2018 3:50 am
by koitsu

Code: Select all

and #%1100     ; We only care about bits 2 and 3
cmp #%1100     ; Are bits 2 and 3 set to 1?
beq YesTheyAre

Re: Problems understanding bit logic

Posted: Sat Nov 17, 2018 3:55 am
by pwnskar
Thank you! :)