mipsmars-simulatorpcspim

Syntax error in MIPS?


So, I'm currently learning MIPS for my Uni degree and I've came across a syntax error that is bugging me, I can't seem to put my finger on where I went wrong, my piece of code is one where a user enters two numbers, and the console is supposed to return a set of numbers that are incremented and finish printing due to the two numbers the user inputs, I'm currently getting a syntax error on PCSpim, which says "spim: (parser) syntax error on line 55 of file" line 55 is addi $t0, $t0, $t2 of the code I'm going to send, if anyone could point me in the general direction of where to fix this it'll be great.

.data
 text: .asciiz "Enter any number: "
 message: .asciiz " After while loop is done "
 str: .asciiz "Enter a number to add: "
 newline: .asciiz "\n"
 space: .asciiz ","

.text

 main:


# Printing out the text
li $v0, 4
la $a0, text
syscall

# Getting user input
li $v0, 5
syscall

# Moving the integer input to another register
move $t1, $v0

# Printing out the newline
li $v0, 4
la $a0, newline
syscall

# Printing out the text
li $v0, 4
la $a0, str
syscall

# Getting user input
li $v0, 5
syscall

# Moving the integer input to another register
move $t2, $v0

# Printing out the newline
li $v0, 4
la $a0, newline
syscall

 # i = 0

 addi $t0, $zero, 0

 while: 

 bgt $t0, $t1, exit
 jal printNumber

 addi $t0, $t0, $t2

 j while

 exit:
    li $v0, 4
    la $a0, message
    syscall

 #End of program
 li $v0, 10
 syscall

 printNumber:
   la $v0, 1
   add $a0, $t0, $zero
   syscall

   li $v0, 4
   la $a0, space
   syscall

   jr $ra

Solution

  • It looks like addi needs the third value to be an immediate vale not a register ... if it is a register it should be add