gpt4 book ai didi

assembly - 运行代码时出现错误 MIPS “spim: (parser) syntax error”

转载 作者:行者123 更新时间:2023-12-03 08:01:56 33 4
gpt4 key购买 nike

我正在使用 MIPS 模拟器。

当我尝试在模拟器中打开包含我的代码的文本文件时发生

我无法理解为什么它不能在 QTSpim 上运行。我得到错误

spim: (parser) syntax error line 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 上运行。

最佳答案

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 

关于assembly - 运行代码时出现错误 MIPS “spim: (parser) syntax error”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60405254/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com