尝试在MIPS中向Array添加浮点值但是出现异常7错误

时间:2013-03-15 20:32:27

标签: arrays mips spim

我必须编写一个程序,允许我在两个20个位置的数组中添加和搜索浮点数(数组HEIGHT和RADIOUS)。我在添加部分时遇到问题...... 我读取了用户输入,然后当我尝试将第一个浮点值添加到数组中时,我得到一个EXCEPTION 7错误...它表示错误的数据地址。我不知道还能做什么...... 我正在使用Spim ..

这是我的代码:

       .data
menu:    .asciiz "\nOptions: \n 0. Exit \n 1. Enter Firework \n 2. Search Inventory \n . . . . . . . . .\n"
option1: .asciiz "Enter the height: \n"
option1b: .asciiz "Enter the radius: \n"
full:    .asciiz "Array is full\n"
height: .space 80 #array with 80 bytes (20 positions)
radius: .space 80 #array with 80 bytes (20 positions)
       .text

pre:
     addi $t1, $zero, 1 #register containing the value 1
     addi $t2, $zero, 2 #register containing the value 2
     la $s0, height #loads array height
     la $s1, radius #loads array radius
     add $t5, $zero, $zero #number of elements in the arrays height and radius
     addi $t7, $zero, 20 #max number of elements in the array

main:
     addi $v0, $zero, 4 
     la $a0, menu #load menus
     syscall #prints string

     addi $v0, $zero, 5
     syscall #reads options

     beq $v0, $zero, exit #goes to exit if option is zero
     beq $v0, $t1, op1 #goes to op1 if option is 1
     beq $v0, $t2, op2 #goes to op2 if option is 2

op1:
    slt $t6, $t5, $t7 #sets $t6 to 1 if (t5 < t7)

    bne $t6, $zero, message #if array height is full goes to message

    addi $v0, $zero, 4 
    la $a0, option1 #loads option1
    syscall #prints string

    addi $v0, $zero, 6
    syscall #reads float value


    swc1 $f0, 0($s0) #adds to array height
    addi $s0, $s0, 4 #advances array in one position

    addi $v0, $zero, 4 
    la $a0, option1b #load option1b
    syscall #prints string

    addi $v0, $zero, 6
    syscall #reads float value


    swc1 $f0, 0($s1) #adds to array radius
    addi $s1, $s1, 4 #advances array in one position

    addi $t5, $t5, 1 #increments counter in 1

    jr $ra

op2:
    j main

message:
    addi $v0, $zero, 4 
    la $a0, full #load menus
    syscall #prints string
    j main    

exit:
    jr $ra

谢谢!

0 个答案:

没有答案