m8si
Active member
I need to know how many of the bits are set in a byte. 0001 = 1, 0010 = 1, 0011 = 2 etc...
I came up this solution but I feel there got to be a better way.
I came up this solution but I feel there got to be a better way.
Code:
LDX #%1111 ;Count set bits of X
TXA
LSR
LSR
LSR
STA temp
TXA
AND #%0100
LSR
LSR
ADC temp
STA temp
TXA
AND #%0010
LSR
ADC temp
STA temp
TXA
AND #%0001
ADC temp
STA temp ; temp is now #4