6502-OS/util/parity.s65

23 lines
535 B
Plaintext
Raw Normal View History

2023-12-31 14:56:24 +01:00
.export count_set_bits
2024-08-08 21:11:25 +02:00
2023-12-31 14:56:24 +01:00
;;********************************************************************************
2024-08-08 21:11:25 +02:00
;; @function Count the number of set bits in the `A` register
2024-08-08 20:39:25 +02:00
;; @modifies A, X, Y
2024-08-08 21:11:25 +02:00
;; @param A: Byte to count the set bits in
2023-12-31 14:56:24 +01:00
;; @returns Y: The number of set bits in the byte
;;********************************************************************************
.proc count_set_bits
2024-01-03 13:08:04 +01:00
ldx #9
2023-12-31 14:56:24 +01:00
ldy #0 ; number of set bits
@loop:
dex
beq @done
ror
bcc @loop
@set:
iny
bra @loop
@done:
rts
.endproc