+3  A: 

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
Sounds good, just one question though how may i go about shifting the value thats being tested one bit to the right?
cardo
Interesting. This is a _very_ limited instruction set. It looks like it doesn't have one. However, you can do it another way. If you check the _top_ bit instead of the bottom, you can emulate a shift left by adding a value to itself. In other words, `add xyz,xyz` will shif t the top bit out and move all the others left. This is a `check top bit, shift left` solution rather than `check bottom bit, shift right` solution but it should still be workable.
paxdiablo