Since it's homework, we're unlikely to give you a direct answer. Some help instead:
- You start a counter at 0.
- You loop until the value you're testing is zero.
- If the least significant bit is one, you increment the count.
- You shift the value you're testing right one bit.
- The counter now contains the number of 1-bits.
- Subtract that from the total bits to get the number of 0-bits.
Processors will usually have store instructions like mov
or ld
. They'll also generally have compare and conditional jumps like cmp
and jnz
.
You can generally use a bitwise AND instruction to get just one bit (and
) and shift instructions such as shr
.
You just have to map that algorithm above to your particular assembler language.
paxdiablo
2010-09-18 06:00:12