4
\$\begingroup\$

I have implemented this MIPS code to determine the length of given ASCII character strings. Is there a simpler way to implement this code? Is there is a built-in function in MIPS?

Given String:

"Hello\n"

Output:

6

.data
    message: .asciiz "Hello\n"
.text

main:
    li $t1,0
    la $t0,message

loop:
    lb   $a0,0($t0)
    beqz $a0,done
    addi $t0,$t0,1
    addi $t1,$t1,1
    j     loop
done:

    li   $v0,1
    add  $a0, $0,$t1
    syscall

    li   $v0,10
    syscall
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.