Error in MIPS assembler regarding fetch address not being aligned

0

having some trouble with an assignment, not looking for solution code, just some answers to why I keep encountering this error.

The program asks the user for 10 digits and then displays the resulting sum (using the stack and recursion).

I know from debugging that the read: portion works fine, but I get the error "Runtime exception at 0x0040005c: fetch address not aligned on word boundary 0x00000001". The error refers to the line in summation: lw $t0, 0($a0)

Not sure what is wrong since I only ever increment by 4 bytes. I've checked other similar questions but couldn't find any clarification. Any help would be greatly appreciated.

.data

A1:     .space 40
input:  .asciiz "please enter a number: "
Str:    .asciiz "the sum is: "


.text

  main:
    li $s1, 0       
    la $t0, A1
    addi $s0, $zero, 0

  read:
    beq $s1, 10, prep
    li $v0, 4          
    la $a0, input       
    syscall 
    li $v0, 5          
    syscall            
    sw $v0, ($t0)       
    addi $t0, $t0, 4      
    addi $s1, $s1, 1        
    j read

  prep:
    la $a0, A1
    addi $a1, $a0, 40
    jal summation

  summation:

    subi $sp, $sp, 8    
    sw $ra, 4($sp)      
    lw $t0, 0($a0)
    sw $t0, 0($sp)      
    sgt $t1, $a0, $a1
    beq $t1, $zero, L1
    addi $v0, $zero, 0
    addi $sp, $sp, 8
    jr $ra

  L1:
    addi $a0, $a0, 4
    jal summation
    lw $a0, 0($sp)
    lw $ra 4($sp)
    addi $sp, $sp, 8
    add $v0, $a0, $v0
    jr $ra
recursion
assembly
stack
mips
asked on Stack Overflow Apr 6, 2018 by a.meyer

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0