clag 0 Newbie Poster

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

int b = 0, x; 
while (x != 0) { 
         b += ((x & 03) == 2); 
    x >>= 1;

I 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:

addu $s0, $ra, $0 #b = 0 store ra
addi $t1,$t0,-4 #save space
loop: beq $t1,$0,L1 
j loop
L1: sw $t3,0($s1)
addu $ra,$0,$s0
jr $ra

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.