Reputation: 171
I'm trying to write a function in MIPS that would take in a string and return the number of character inside the string. This is what I have so far
# Program to calculate string length of any given string
.data
mystring: .asciiz "Hello, World!"
answer: .word 0
.text
.globl main
main: la $a0, mystring # Load base adress of the string into function argument
jal strlen # jump to strlen and save position to $ra
sw $vo, answer # Store the answer to memory
li $v0, 10 #exit
syscall
strlen: li $v0, 0 # Initialize counter = 0
stringLoop: lb $t0, 0($a0) # Load first word of the string
beq $t0, $zero, end # if $t0 == '\0' then exit the loop
addi $a0, $a0, 1 # Increment the address (go to the next character)
addi $v0, $v0, 1 # Increment the counter
b stringLoop
end: jr $ra # Return to main program
Everytime I try to run it with QtSpim, it gives me a syntax error at the line "sw $vo, answer". Could someone please tell me what is wrong with my program? Thanks
Upvotes: 1
Views: 304
Reputation: 4288
Syntax errors are often caused by typos as in your case. You accidentally wrote vo
instead of v0
.
Upvotes: 2