我收到一个错误,其中blt导致我的程序崩溃,异常7。
它发生在PMIN中
该程序的目的是从用户那里获取最多100个整数。输入整数并输入负值以停止收集循环后,将显示总和和最小值
.data
MSG: .asciiz "Enter integer values, one per\nline, terminated by a
negative\nvalue.\n"
EMSG: .asciiz "The program has terminated."
SUM: .asciiz " Sum is: "
MIN: .asciiz " Min is: "
MAX: .asciiz " Max is: "
MEAN: .asciiz " Mean is: "
VAR: .asciiz "Variance is: "
CR: .byte '\n'
.align 2
ARRAY: .space 400
.align 2
.text
.globl main
main:
li $t1,0 #Element counter
li $t2,0 #Max Elements
li $t3,0 #Mem counter
li $v0,4 #Syscall print message
la $a0,MSG #MSG
syscall
LOOP:
li $v0,5 #Syscall accept user input
syscall
blt $v0,$zero,CSUM #If input is less than zero branch to CSUM
sw $v0,ARRAY($t3) #Store user input into array at space t3
addiu $t3,$t3,4 #Add 4 to mem counter
addiu $t1,$t1,1 #Add 1 to element counter
addiu $t2,$t2,1 #Add 1 to max elements
bne $t1,100,LOOP #Branch back to LOOP if t1 != 100
CSUM:
li $t1,0 #Set t1 back to 0
li $t3,0 #Set t3 back to 0
li $t5,0 #Total sum
A:
lw $s0,ARRAY($t3) #Store Array element t3 into s0
add $t5,$t5,$s0 #Add Array element stored in s0 to t5
addiu $t3,$t3,4 #Add 4 to mem counter
addiu $t1,$t1,1 #Add 1 to element counter
bne $t1,$t2,A #If t1 != t2 branch to A
PSUM:
li $v0,4 #Syscall print message
la $a0,SUM #SUM
syscall
li $v0,1 #Syscall print integer
move $a0,$t5 #Move t5 to a0
syscall
li $v0,11 #Syscall print byte
lb $a0,CR #CR
syscall
PMIN:
li $t1,0 #Set t1 back to 0
li $t3,0 #Set t3 back to 0
addiu $t6,$t2,-1
B:
lw $s2,ARRAY($t3)
addiu $t1,$t1,1
addiu $t3,$t3,4
lw $s3,ARRAY($t3)
blt $s3,$s2,MI
blt $s2,$s3,MI
bne $t6,$t1,B
j PrintMIN
MI:
move $s5,$s2
j B
PrintMIN:
li $v0,4
la $a0,MIN
syscall
li $v0,1
move $a0,$s5
EXIT:
li $v0,4 #Syscall print message
la $a0,EMSG #EMSG
syscall
jr $ra #Exit