;
;       CPE 221 Assembly Examples
;       This example has pseudocode rather than C
;
;       count = 0
;       for each bit in r0
;         rotate that bit into carry
;         if carry == 1 count = count + 1
;
        AREA   COUNT_ONES, CODE, READONLY
        ENTRY
		LDR    r0, =47231        ; initializ r0
        LDR    r4, =0            ; initialize i
        MOV    r1, #0            ; initialize count
loop    CMP    r4, #32           ; more bits to do?
        BPL    done              ; no, done
       ; MOVS   r0, r0, ROR #1   ; rotate through carry bit
        RRXS   r0, r0            ; another way of doing it 
        ADDCS  r1, r1, #1        ; if carry == 1 count++
        ADD    r4, r4, #1		 ; look at next bit
        BAL    loop
done    B      done
        END
