I know I could use a loop or a table. Any other way/trick?
0 -> $01
1 -> $02
2 -> $04
3 -> $08
Code: Select all
; ORA can set your bit, preserving all others LDX index LDA value ORA bit_set, x STA value ; EOR can flip your bit, preserving all others LDX index LDA value EOR bit_flip, x STA value ; AND can clear your bit, preserving all others LDX index LDA value AND bit_clear, x STA value bit_set: bit_flip: .db $01, $02, $04, $08, $10, $20, $40, $80 ; bits 0-7 bit_clear: .db $FE, $FD, $FB, $F7, $EF, $DF, $BF, $7F ; bits 0-7, negated
Clearing a single bit using AND requires a negated bit, like #%11111011, for bit 2, for example.
Perhaps code cannot be in the 1st column of text (reserved for labels and assembler directives) and thus needs spaces or a tab before it?
Also, you're not putting a data table in between valid instructions, are you? Your "lda table,x" at least needs its own label if code is going to JSR or jump to it.