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 verify it.
This is the C function
int strlen(char *s) {
int len;
len=0;
while(*s != '\0') {
len++;
s++;
}
return len;
}
Thanks!
strlen:
add $v0, $zero, $zero
loop:
lbu $t0, 0($a0)
addi $a0, $a0, 1
addi $v0, $v0, 1
bne $t0, $zero, loop
s_end:
addi $v0, $v0, -1
j $ra