Converting C into MIPS Assembly

Hi, I wanted to convert this code into assembly but I'm having trouble. Here's what I got :]

Code:

`int b = 0, x; `

while (x != 0) {

b += ((x & 03) == 2);

x >>= 1;

believe this is just a basic instruction to count the number of occurrences of the bit sequence “10” (one zero) in x.

Now to convert this, here's what I got:

Code:

`L1: bne $s1, $zero, DONE # branch if ! ( x ==0j )`

addu $s0, $ra, $0 #b = 0 store ra

add $s1, $s1, $s2 # b+=$s2

beq $s2, $s2, 2 b += ((x & 03) == 2

addi $s3, $s3, 1 # x>>=1

j L1 # jump back to top of loop

DONE:

but I'm thinking that there are some logical issues with this ASM code. Is there a different way to approach this conversion? Thanks :]