Error code: Runtime exception at 0x00400010: address out of range 0x00000000

34 Views Asked by At

.data prompt1: .asciiz "This program reads in a String from the user and then allows the user to make changes to it until they want to stop.\n" prompt2: .asciiz "Please enter your string now (maximum of 40 characters):\n" prompt3: .asciiz "Your current string is:\n" prompt4: .asciiz "Do you want to make any changes to the string? (Y/N): " prompt5: .asciiz "Enter the character in the string you would like replaced: " prompt6: .asciiz "Enter what you would like to change the character to: " prompt7: .asciiz "Your final string is:\n"

.text .globl main

swap_characters: addi $sp, $sp, -8
sw $ra, 4($sp)
sw $s0, 0($sp)

move $s0, $a0      

loop: lb $t0, 0($s0)
beqz $t0, done
beq $t0, $a1, replace

addiu $s0, $s0, 1  
j loop

replace: sb $a2, 0($s0)
addiu $s0, $s0, 1
j loop

done: lw $ra, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, 8
jr $ra

main:

li $v0, 4
la $a0, prompt1
syscall


li $v0, 4
la $a0, prompt2
syscall


li $v0, 8
la $a0, 0($v1)      
li $a1, 40         
syscall


li $v0, 4
la $a0, prompt3
syscall


li $v0, 4
la $a0, 0($v1)      
syscall

change_loop: # Prompt for making changes li $v0, 4 la $a0, prompt4 syscall

li $v0, 12
syscall


beqz $v0, done1      


li $v0, 4
la $a0, prompt5
syscall


li $v0, 12
syscall


move $a1, $v0


li $v0, 4
la $a0, prompt6
syscall


li $v0, 12
syscall


move $a2, $v0


move $a0, $v1      
jal swap_characters


li $v0, 4
la $a0, prompt3
syscall

# Print the updated string
li $v0, 4
la $a0, 0($v1)      
syscall

j change_loop

done1:

li $v0, 4
la $a0, prompt7
syscall


li $v0, 4
la $a0, 0($v1)      


li $v0, 10
syscall

I thought I had the program done correctly and it won't run. What did I do wrong. This is an assignment for class. It is happening on the line lb $t0, 0($s0) in the loop. Can anyone help?

0

There are 0 best solutions below