A83: Re: Setting a bit...


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

A83: Re: Setting a bit...




Use a lookup table and an xor operation:

; a = value to change, c = bit to change (starting at 0)
; 8b / 39t (16b total)

 ld b,0
 ld hl,BitMasks
 add hl,bc
 ld b,(hl)
 xor b

BitMasks:
 .db $1, $2, $4, $8, $10, $20, $40, $80



> Ok, question here...what's a good way to toggle the nth bit of a byte when
n is stored in
> a register? For example:
>
>  ld a,3
>
> ;
> ; Necessary code here
> ;
>
> And the 3rd bit is set/reset. I thought of creating a bitmask on-the-fly
then XORing it,
> or perhaps making a lookup table...but I'm still not too sure. Help? :)




Follow-Ups: References: