So I need to count bits on a integer this is my code but I don't know why is not working, I sent a hex value from c main and somehow I have to shift it and mask it. I'm kind of lost, I guess I'm getting a wrong answer because I don't know how to shift and mask, But I think I kind of know what I'm doing with the loops and the adding. again I need to count until 32 the bits that are 1 not zeros, but I'm getting a wrong answer, for example 6 110 it would be 2 bits. this is a homework so I cant use a built in function or whatever haha.
.global hi
hi:
save %sp,-1024,%sp
clr %i0
clr %i1
clr %i2
loop:
cmp %i2,32
be,a away
mov %l7,%i0
add 1,%i2,%i2
and %i0,1,%l1
cmp %l1,1
be count
nop
!srl %i0,%l2,%10
!mov %l2,%i0
!and %i0,1,%i0
srl %i0,1,%i0
ba loop
nop
!mov %l2,%i0
count:
add 1,%l7,%l7
away:
ret
restore
Why is this not working yet? I followed it that c implementation and still is not returning the number of bits :/. the return value is %i0 and I have no idea how to jump back to the loop after incrementing counter.
So what is this doing? when it says ba loop isn't it supposed to go back to loop?
So I don't know if is much to ask but, do you have any idea of how to fix this issue? :p because I don't really know, I'm looking at the manual and I don't see anything that can help me :/.