2015-05-05 102 views
0

我想编写一个程序来检查两个数组的大小,确保它们小于某个值(99),并确保它们的总和也小于一个值( 99)。然而,这两个阵列大小的总和正被放入R13但如果这些值大于99MIPS检查数组中的元素数

.data 
arrayOne: .word 5 1 3 6 7 8 
arrayTwo: .word 3 5 7 9 
arrayMerged: .word 99 

.text 
main: 
ld r1, arrayOne(r0) ;load the num elements into r1 
ld r2, arrayTwo(r0) ;load the num elements into r2 
lui r31, 99 
slt r30, r1, r31 ;check to see if r1 is larger than 99 
beq r30, r31, l3  ;if r1 is larger than 99, goto l3 
slt r30, r2, r31 ;check to see if r2 is larger than 99 
beq r30, r31, l3  ;if r2 is larger than 99, goto l3 
dadd r13, r1, r2 ;add the sum of r1 and r2 and store in r13 
slt r30, r13, r31 ;check to see if the sum of arrayOne and arrayTwo is larger than 99 
beq r30, r31, l3  ;if r13 is larger than 99, goto l3 

l3: halt 
+0

您正在使用'lui r31,99',您应该使用'li r31,99'。但是你应该遵循MIPS寄存器使用惯例,特别是'r31'保留给当前例程的返回地址。 – markgz

回答

0
  • r1并且这样不是有效的寄存器命名它不断裂。你要么$1$at(顺便说一句,你不应该使用寄存器1,IIRC它是保留)。
  • MIPS中没有halt指令。你想要的是一个系统调用退出。
+0

下调解释欢迎。 – m0skit0