Solving MIPS Runtime Error: Address Out of Range 0x00000000

In summary, the conversation is about a runtime error that occurs in a piece of code. The person is unsure of the cause and asks for ideas. The code involves swapping and sorting numbers in an array. They also mention running the code through a low level debugger to access register values.
  • #1
m00nbeam360
20
0
Hi there,

Not sure if this is the right place to post, but I seem to get a runtime error that says: address out of range 0x00000000. I think that it's probably in the first three lines of my code, but any idea as to what else it may be? Thanks so much!
Code:
	.data
save:   .word 1,2,4
size:   .word 3
	.text
	
swap:   sll $t1, $a1, 2 #shift bits by 2 
	add $t1, $a1, $t1 #set $t1 address to v[k]
	lw $t0, 0($t1) #load v[k] into t1 <--- ERROR 
	#lw $t2, 4($t1) #load v[k+1] into t1
	#sw $t2, 0($t1) #swap addresses
	#sw $t0, 4($t1) #swap addresses
	jr $ra #return 

sort:   addi $sp, $sp, -20 #make enough room on the stack for five registers
	sw $ra, 16($sp) #save the return address on the stack
	sw $s3, 12($sp) #save $s3 on the stack
	sw $s2, 8($sp) #save Ss2 on the stack
	sw $s1, 4($sp) #save $s1 on the stack
	sw $s0, 0($sp) #save $s0 on the stack
	
	move $s2, $a0 #copy the parameter $a0 into $s2 (save $a0) 
	move $s3, $a1 #copy the parameter $a1 into $s3 (save $a1)
	move $s0, $zero #start of for loop, i = 0
for1tst: slt $t0, $s0, $s3 #$t0 = 0 if $s0 S $s3 (i S n)
	beq $t0, $zero, exit1 #go to exit1 if $s0 S $s3 (i S n)
	addi $s1, $s0, -1 #j - i - 1
for2tst: slti $t0, $s1, 0 #$t0 = 1 if $s1 < 0 (j < 0) 
	bne $t0, $zero, exit2 #$t0 = 1 if $s1 < 0 (j < 0)
	sll $t1, $s1, 2 #$t1 = j * 4 (shift by 2 bits)
	add $t2, $s2, $t1 #$t2 = v + (j*4) 
	lw $t3, 0($t2) #$t3 = v[j]
	lw $t4, 4($t2) #$t4 = v[j+1]
	slt $t0, $t4, $t3 #$t0 = 0 if $t4 S $t3
	beq $t0, $zero, exit2 #go to exit2 if $t4 S $t3
	move $a0, $s2 #1st parameter of swap is v(old $a0)
	move $a1, $s1 #2nd parameter of swap is j
	jal swap #swap
	addi $s1, $s1, -1 
	j for2tst #jump to test of inner loop
	j print
exit2: 
	addi $s0, $s0, 1 #i = i + 1
	j for1tst #jump to test of outer loop
	
exit1: 
	lw $s0, 0($sp) #restore $s0 from stack
	lw $s1, 4($sp) #resture $s1 from stack
	lw $s2, 8($sp) #restore $s2 from stack
	lw $s3, 12($sp) #restore $s3 from stack
	lw $ra, 16($sp) #restore $ra from stack
	addi $sp, $sp, 20 #restore stack pointer 
	jr $ra #return to calling routine
	
	.data
space:.asciiz  " "          # space to insert between numbers
head: .asciiz  "The sorted numbers are:\n"
      .text
print:add  $t0, $zero, $a0  # starting address of array
      add  $t1, $zero, $a1  # initialize loop counter to array size
      la   $a0, head        # load address of print heading
      li   $v0, 4           # specify Print String service
      syscall               # print heading
out: 
      li   $v0, 1           # specify Print Integer service
      la   $a0, space       # load address of spacer for syscall
      li   $v0, 4           # specify Print String service
      syscall               # output string
      addi $t0, $t0, 4      # increment address
      addi $t1, $t1, -1     # decrement loop counter
      bgtz $t1, out         # repeat if not finished
      jr   $ra              # return
 
Technology news on Phys.org
  • #2
Hey m00nbeam360.

Just out of curiosity, have you run this code through a low level debugger where you get access to the register values? (Even if you have to use some sort of emulator program)

I can't really speculate what it's in the values, but if you for example over-writing a value or trying to load in the contents at address 0x0 when something has been cleared then the register contents will reflect that.

Also are those numbers in your mneumonics some kind of offset you provide with the register?
 

1. What is a MIPS Runtime Error?

A MIPS Runtime Error is an error that occurs when running a program written in the MIPS assembly language. It indicates that the program has tried to access a memory address that is outside of the range of valid addresses.

2. What does "Address Out of Range 0x00000000" mean?

This means that the program has attempted to access the memory address 0x00000000, which is not a valid address. This address is often referred to as "null" and is typically reserved for special purposes, such as indicating an error or the end of a data structure.

3. How can I fix a MIPS Runtime Error?

In order to fix a MIPS Runtime Error, you will need to carefully review your code and identify where the error is occurring. Make sure that all memory addresses being accessed are within the valid range and that your program is not trying to access a null address. You may also need to check for any logical errors in your code that could be causing the error.

4. Can a MIPS Runtime Error be prevented?

Yes, a MIPS Runtime Error can be prevented by carefully writing and testing your code before running it. Make sure to thoroughly check for any potential errors or issues with memory access. Additionally, using debugging tools and techniques can help catch and prevent runtime errors.

5. Are there any common causes for a MIPS Runtime Error?

One common cause of a MIPS Runtime Error is trying to access an array element or variable that is out of bounds. This means that the program is trying to access memory that is outside of the allocated space for that array or variable. Other causes may include incorrect use of pointers or addressing modes in the code.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Programming and Computer Science
Replies
5
Views
9K
  • Programming and Computer Science
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
7K
  • Programming and Computer Science
Replies
4
Views
20K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
5
Views
6K
Back
Top