MIPS Address out of range (MARS); Beginner


I'm trying to understand some code. I'm still at the very beginning of MIPS. I tried to get it run on Mars to understand whats happening step by step. However it's stops at line 6: Runtime exception at 0x0040000c (refers to line 6): address out of range 0x000003ec.

I tried to find a solution by looking throught other posts here, however wasn't able to identify the problem.

add  $t6, $t0, $t0
addi $t4, $t0, 0x7
andi $t3, $t4, 0x4
lw   $t2, 0x3e8($t3)
add  $t6, $t3, $t6
addi $t5, $t4, 1
sub  $t1, $t2, $t6
bne  $t5, $t6, loop
sw   $t6, 0x400($t1)

If you could hepl me out I would really appreciate it!

asked on Stack Overflow Dec 22, 2019 by Jonas

1 Answer


This strange code is either going to load from 0x3e8 or 0x3ec, depending on what is in $t0 to start.

Both of those are unusually low memory locations, which don't store anything of interest, and are typically protected to detect program faults.

Generally speaking we want to see memory addresses in certain ranges that are assigned to various kinds of content.  While not at all comprehensive, the following should give some idea of expectations for a simple program in MARS:

  • code in the range of 0x00400000 to 0x004FFFFF,
  • global data in the range of 0x10010000 to 0x1003FFFF,
  • heap data in the range of 0x10040000 to 0x1FFFFFFF,
  • stack data in the range of 0x70000000 to 0x7FFFFFFF

Addresses wildly outside of the ranges designated for valid content will usually (but not always) cause a fault, because these addresses are not valid, so something in the program went wrong — the program is trying to access memory that does not belong to valid data or instructions (e.g. global, heap, stack, or code)

You will have to debug the larger code to understand what it is trying to do and see where it is going wrong in that, and thus why this fault might be happening.

answered on Stack Overflow Dec 22, 2019 by Erik Eidt • edited Dec 22, 2019 by Erik Eidt

User contributions licensed under CC BY-SA 3.0