.export count_set_bits ;;******************************************************************************** ;; @function Count the number of set bits in the `A` register ;; @modifies A, X, Y ;; @param A: Byte to count the set bits in ;; @returns Y: The number of set bits in the byte ;;******************************************************************************** .proc count_set_bits ldx #9 ldy #0 ; number of set bits @loop: dex beq @done ror bcc @loop @set: iny bra @loop @done: rts .endproc