0

The problem looks to be when the user input is stored in the array. With the error "address error in store" after every input. "Exception occurred at PC=0x0040008c" and "Unaligned address in store: 0x10010043." I believe that the problem has to do with "sw $v0,array($t0)"

ISSUE: .space isn't implicitly word aligned, so when writing words to it you must take care to not misalign it in its declaration inside the .data segment. In my case, .space was misaligned by the prompts.

<sup>
    .text 
main: 
    la $a0,prompt1
    li $v0,4
    syscall 

    li $t4,4
    li $t0,0

store:
    #check if 20 == input;
        beq $t6,20,display

        #print the 2nd prompt
    la $a0, prompt2
    li $v0,4
    syscall

    #take in user input
        li $v0, 5
        syscall

    #check for sentinal value
    beq $v0,-1,display

    #store user input into array
        sw $v0,array($t0)

    #add 4 to the index
        add $t0,4
    
    j store

display:
    beq $t0,0,load
    
    lw $t1,array($t2)
    
    li $v0,1
    move $a0,$t1
    syscall
    
    add $t2,4 
    add $t0,-4

    j display
    
load:
    la $t4,array

    li $v0,10
    syscall 


    .data
prompt1:    .asciiz "Enter 5 numbers into an array (or quit -1)\n"
prompt2:    .asciiz "Enter a number : "
array:      .space 20
</sup>
Bryqnz
  • 1
  • 1

0 Answers0