2016-09-20 48 views
0

我的代码出现了Unsupported R-Type,我如何使它减去正确。试图改变其他细节....已经尝试使用subu ..................................... .................................................. ........MIPS-如何减去(已经使用过的子不起作用!)

.data 
 
str: .asciiz "\nHello World!\n" 
 
# You can change what is between the quotes if you like 
 

 
.text 
 
.globl main 
 

 
main: 
 
# Do the addition 
 
# For this, we first need to put the values 
 
# to add into registers ($t0 and $t1) 
 
li $t0, 30 # You can change the 10 
 
li $t1, 20 # You can change the 20 
 

 
# Now we can add the values in $t0 
 
# and $t1, putting the result in special register $a0 
 
sub $a0, $t0, $t1 
 

 
# Set up for printing the value in $a0. 
 
# A 1 in $v0 means we want to print an int 
 
li $v0, 1 
 

 
# The system call looks at what is in $v0 
 
# and $a0, and knows to print what is in $a0 
 
syscall 
 

 
# Now we want to print Hello World 
 
# So we load the (address of the) string into $a0 
 
la $a0, str 
 

 
# And put a 4 in $v0 to mean print a string 
 
li $v0, 4 
 

 
# And just like before syscall looks at 
 
# $v0 and $a0 and knows to print the string 
 
syscall 
 

 
# Nicely end the program 
 
li $v0, 0 
 
jr $ra

回答

1

你的程序运行在marsspim模拟器除了的程序终止罚款。这些模拟器不设置$ra,所以它是零。所以,最后,你要回到可能有半随机指令的东西,包括非法指令。因此,它的不是你的sub就是这个问题。这是后来发生的事情。

变化:

# Nicely end the program 
li $v0, 0 
jr $ra 

分为:

# Nicely end the program 
li $v0, 10 
syscall