I have a simple question for a Comp Sci class I\'m taking where my task is to convert a function into MIPS assembly language. I believe I have a correct answer but I want to ver
(Editor's note: the add of -1
after the loop corrects for off by 1 while still allowing an efficient do{}while loop structure. This answer proposes a more literal translation from C into an if() break
inside an unconditional loop.)
I think the while loop isn't right in the case of *s == 0
.
It should be something like this:
...
lbu $t0, 0($a0)
loop:
beq $t0, $zero, s_end # *
...
b loop
s_end:
...
*You could use a macro instruction (beqz $t0, s_end) instead of beq instruction.