I'm testing a simple assembly function (SPARC). The function is below and should take two parameters, x
and *str
, and count the number of times x
occurs in *str
. The function is, however, resulting in an infinite loop. I'm using C to call the assembly function, and that is also below. What could be causing the infinite loop? To clarify, the assembly function repeatedly moves to eq
and continually increments l0
.
Assembly:
.global occurs
occurs: mov 0, %l0 !l0 will be counter
loop: ldsb [%o1], %o2 !get current value, store in o2
cmp %o2, 0 !if current value is terminating 0, end program
be end
nop
cmp %o0, %o2 !if two are equal, increment l0
be eq
nop
inc %o1 !increment o1 to check next address
ba loop
nop
eq: inc %l0
ba loop
nop
end: mov %l0, %o0 !store final result in o0
retl !return value
nop
C function call:
char x = 'A';
char str3[64] = "AaAbBbA";
int oc = occurs(x, str3);
printf("%d", oc);