Problems understanding bit logic

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
pwnskar
Posts: 119
Joined: Tue Oct 16, 2018 5:46 am
Location: Gothenburg, Sweden

Problems understanding bit logic

Post 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!
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Problems understanding bit logic

Post 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
pwnskar
Posts: 119
Joined: Tue Oct 16, 2018 5:46 am
Location: Gothenburg, Sweden

Re: Problems understanding bit logic

Post by pwnskar »

Thank you! :)
Post Reply