Я получаю ошибку MIPS «spim: (синтаксический анализатор) синтаксическая ошибка» при запуске кода - PullRequest
1 голос
/ 26 февраля 2020

Я использую симулятор MIPS.

Происходит, что при попытке открыть текстовый файл, содержащий мой код в симуляторе

У меня возникают проблемы с пониманием, почему это будет не работает на QTSpim. Я получаю ошибку

spim: (синтаксический анализатор) строка с синтаксической ошибкой 8

Код:

#This program read the given array value one by one
#then compare and find largest
#Display largest and it's count

#Data declaration
.data 
a: .word 5,2,15,3,7,15,8,9,5,2,15,3,7                             #Initialize an array
space: .asciiz " "                                                #Get space
nextLine: .asciiz "\n"                                            #for \n
big: .asciiz "bigger....\n"                                       #Display bigger   
small: .asciiz "smaller....\n"                                    #Display smaller
equal: .asciiz "same....\n"                                       #Display same
#Output display strings
Largest: .asciiz "The largest number is "
LargestCount: .asciiz "The largest number is included "
times: .asciiz " times\n"
#Main program
.text
.globl main
main:
la $s0,a                                              #Get the address of the array
addi $s1,$0,13                                        #size of the array
addi $s2,$0,0                                        #for largest number
addi $s3,$0,0                                        #For largest count
addi $t0,$0,0                                        #i
addi $t1,$0,0                                        #j

#Loop for array data print
Loop:
beq $t0,$s1,nextLoop                               #check the counter reach array size
    lw $a0,0($s0)                                      #Get value from array to print
addi $v0,$0,1                                      #Integer print system caa
syscall                                            #Print integer value in a0
la $a0,space                                       #get the address of space string
addi $v0,$0,4                                      #System call to print string
syscall                                            #Print space
addi $t0,$t0,1                                     #Increment counter
addi $s0,$s0,4                                    #to get next data contain address
j Loop                                           #repeat loop

#Find larget and it's count
nextLoop:
la $a0,nextLine                                  #get the address of \n print
addi $v0,$0,4                                    #String print system call
syscall                                          #print string
addi $t0,$0,0                                      #for loop counter
la $s0,a                                          #Get the address of the array
#Loop through array value
forLoop:
beq $t0,$s1,print                                  #check the counter reach array size  
move $a1,$s2                                       #For compare method argument
lw $a0,0($s0)                                      #Get value from array
jal compare                                       #call compare function
addi $t1,$v0,0                                   #j=compare(largest,a[i])
beq $t1,0,biggest                               #If the compare result 0 means value bigger
beq $t1,1,same                                   #If the compare result 1 means same value
beq $t1,2,smallest                              #If the compare result 2 means value smaller

#Bigger case
biggest:
la $a0,big
addi $v0,$0,4
syscall
lw $s2,($s0)
addi $s3,$0,1
addi $t0,$t0,1
addi $s0,$s0,4
j forLoop
#Same case
same:
la $a0,equal
addi $v0,$0,4
syscall
addi $s3,$s3,1
addi $t0,$t0,1
addi $s0,$s0,4
j forLoop
smallest:
#Smaller case
la $a0,small
addi $v0,$0,4
syscall
addi $t0,$t0,1
addi $s0,$s0,4
j forLoop

#Print result
print:
la $a0,Largest                       #Largest string display string address
addi $v0,$0,4                       #System call to print string
syscall                             #print
move $a0,$s2                       #To pri t largest number move into a0
addi $v0,$0,1                     #System call to print integer
syscall                           #Integer print
#Print \n
la $a0,nextLine
addi $v0,$0,4
syscall
#Print largest count atring
la $a0,LargestCount
addi $v0,$0,4
syscall
#Print count
move $a0,$s3
addi $v0,$0,1
syscall
#Times string print
la $a0,times
addi $v0,$0,4
syscall
#End of the program
exit:
addi $v0,$0,10                                     #Terminate the program normally system call
syscall                                             #End the program  
#Compare method
compare:
move $t3,$ra
jal subt                                           #Call subtract function
bgt $v0,0,return2                                 #If sub value greaterthan 0 return 2
beq $v0,0,return1                                 #If sub value = 0 return 1
addi $v0,$0,0                                     #Other wise return 0 as result
move $ra,$t3
jr $ra                                            #Return to main

#Return value 2 as result of the function call
return2:
addi $v0,$0,2
move $ra,$t3
jr $ra
#Return value 1 as result of the function call
return1:
addi $v0,$0,1
move $ra,$t3
jr $ra
#Subtract function
subt:
sub $v0,$a1,$a0
jr $ra

Это работает на MARS, и я не уверен, почему он не работает и на QTSpim.

1 Ответ

0 голосов
/ 28 февраля 2020
a: .word 5,2,15,3,7,15,8,9,5,2,15,3,7

заменить , пробелом. mips не займет ,

Попробуйте:

a: .word 5 2 15 3 7 15 8 9 5 2 15 3 7 
...