I am trying to learn the MIPS assembly language for my CS class. I am struggling syntactically trying to write this program. I have looked at the other example my professor gave us and I followed it closely. I am getting an error on my branch not equal condition. The code is as follows.
# Main program that will call subroutine fib to calculate the fibonacci and
# print the result
.text
.globl main
sub $sp,$sp,4
sw $ra,0($sp)
li $a0,3
jal fib
la $a0,str
syscall
sw $a0,0($v0)
syscall
lw $ra,0($sp)
add $sp,$sp,4
jr $ra
.data
str:
.asciiz "fib = "
.text
fib:
sw $a1,0($a0)
bne $a0,$0,1 # Branch if the argument is not equal to zero
add $v0,$0 # If it is equal to 0,add 0 to the return value.
addi $t0,$0,1 # Create temporary equal to 1.
bne $a0,$t0,1 # Branch if argument is not equal to 1.
addi $v0,1 # If it is,add one to the return value.
addi $sp,$sp,-4 # Create space on the stack for the return value.
sw $ra,0($sp) # Save old return address to the stack
addi $a0,-1
jal fib #jump to fib and save address
addi $a0,$a1,-2 #subtract 2 from the starting number.
jal fib
lw $ra,0($sp)
add $sp,$sp,4
jr $ra
I know that this code will not work properly as of right now. However, I am not asking for help programming this function, I would just like to be able to run it so I can see what is going on. Before I can even load the file I am getting a syntax error on the following line.
bne $a0,$0,1 # Branch if the argument is not equal to zero
The error reads as follows.
spim: (parser) syntax error on line 35 of file ...
bne $a0,$0,1 #Branch if the argument is not equal to zero
^
Any and all help would be greatly appreciated with this! Thank you so much!