MIPS检查数组中元素的数量

时间:2015-05-05 18:06:40

标签: assembly mips

我正在尝试编写一个程序来检查两个数组的大小,确保它们小于某个值(99),并确保它们的总和也小于值(99)。但是,两个数组大小的总和被放入r13中,但如果值大于99则不会中断

.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

1 个答案:

答案 0 :(得分:0)

  • r1这样的寄存器命名无效。你想要$1$at(顺便说一句,你不应该使用寄存器1,IIRC是保留的。)
  • MIPS中没有halt条指令。你想要的是一个系统调用出口。