Nios/popcount

From ASMBits

nios/bswapPrevious

Write a function that returns the number of 1 bits in a given 32-bit integer (also known as population count).

int popcount (int n);

Expected solution length: Around 10 lines.

Sample Input

5
255

Sample Output

2
8

Make sure you test all of the corner cases (What's the smallest possible answer? Largest?).

Write your solution here

x
 
1
.global _start
2
_start:
3
    movia r4, 5
4
    call popcount
5
    1: br 1b    # Done
6
7
# Only your function (starting at popcount) is judged. The test code above is not executed.
8
popcount:
9
    
10
    
Upload a source file...