#Count # of 1's in a word .macro newLine #macro to print a new liine li $v0 11 li $a0, 10 #linefeed is 10 syscall .end_macro .macro PHex (%value) #prints out an int in hex li $v0, 34 move $a0, %value syscall .end_macro .macro PInt (%value) #prints out an int in hex li $v0, 1 move $a0, %value syscall .end_macro .data A: .word 0x77777777 .text lw $t1, A #word we are going to scan li $t2, 32 #32 bits in a word move $t3,$0 #Initialize a bit counter loop: beqz $t2, end #loop 32 times and $t4,$t1,0x1 #mask only leaving the 1st bit beqz $t4, skip #if it is a 1 count it addi $t3,$t3,1 skip: srl $t1,$t1,1 #shift right sub $t2,$t2,1 #dec counter b loop end: PInt($t3) newLine li $v0, 10 syscall