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
loop:
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!
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:
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.
User contributions licensed under CC BY-SA 3.0