My MIPS implementation, looping over strings: I keep getting:
- Exception occurred at PC=0x10010010
- Bad address in text read: 0x10010010
NOT sure of why this is happening, I tried debugging and stepping. If, anyone knows exactly what's wrong in this code, please answer. I am continuing to try to debug..
YES, this is the ENTIRE code, feel free to run it in QtSpim.
.data
STR_str:
.asciiz "Cow, Bird, Beer"
.text
loop_over_strings:
addi $sp, $sp, -4
sw $ra, 0($sp)
sw $a1, 8($sp)
loop:
sw $a0, 4($sp)
lb $t0, 0($a0)
beqz $t0, end_loop
jalr $a1
lw $a0, 4($sp)
lw $a1, 8($sp)
addi $a0, $a0, 1
j loop
end_loop:
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
.text
.globl main
main:
addi $sp, $sp, -4 # PUSH return address
sw $ra, 0($sp)
la $a0, STR_str
la $a1, ascii
jal loop_over_strings
lw $ra, 0($sp) # POP return address
addi $sp, $sp, 4
jr $ra
CodePudding user response:
In loop_over_strings
, you're allocating 4 bytes of stack space but its using 12, so something is going to be overwritten — that something being overwritten is probably someone else's stacked return address.
CodePudding user response:
You've placed some of your code in the .data
section. It needs to be in the .text
section.