0

I have to write a program that allow me to add and search float numbers in 2 arrays of 20 positions each (arrays HEIGHT and RADIOUS). I'm having trouble with the adding part... I read the user input then when I try to add the first float value into the array I get an EXCEPTION 7 error ... it says bad data adress. I don't know what else to do... I'm using Spim..

Here is my code:

       .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

Thanks!

otavio1992
  • 712
  • 2
  • 6
  • 18
  • 1
    So have you checked at which line the exception occurs and what the register contents were at that point? – Michael Mar 15 '13 at 20:49
  • It doesn't specify the line, but I'm pretty sure its when I try to insert the first value into the array because I know it's reading the user input all right. Im getting this error: Exception occurred at PC=0x00400084 Bad address in data/stack read: 0x00000000 – otavio1992 Mar 15 '13 at 21:20

0 Answers0