How about
lda status
and #%11111110 ; set bit 0 to false
sta status
Note that all other bits are not touched, since 1 AND X
is always X
for every bit. Only bit 0 changes since 0 AND X
is always 0
.
Question
Still new to bitwise operations in 6502 assembly. I would like to have a byte that has 8 flags. This will store the status of my meta-sprite.
I want to be able to set specific flags without altering the others.
I know how to use ORA to set them to one:
lda status
ora #%00000001 ; set bit 0 to true
sta status
I know how to use EOR to toggle them:
lda status
eor #%00000001 ; if bit 0 = true, then bit 0 = false and vise versa
sta status
Lastly, I know how to check if a bit is true:
lda status
and #%00000001 ; if bit 0 = true then set overflow flag to true
But how to set a specific flag to 0, without altering any others? Even if I used AND, how would I force it to set the desired bit to 0?
Thanks, I'm sure I'm missing something simple.
Solution
How about
lda status
and #%11111110 ; set bit 0 to false
sta status
Note that all other bits are not touched, since 1 AND X
is always X
for every bit. Only bit 0 changes since 0 AND X
is always 0
.
OTHER TIPS
I'm not familiar with 6502 specifically, but to clear a bit you generally AND with a value that has every bit set except the one you want to clear.