.export count_set_bits ;;******************************************************************************** ;; @function Initialize the PS2 keyboard ;; @details ;; Count the number of set bits in Y. ;; ;; @modifies A, X, Y ;; @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