MIPS Runtime Error "Cannot read diectly from text segment"


The block of code starting from jal next is given in the question, so it can't be changed (have to give intermediate memory and register states after each instruction). The program terminates at the error line with the mesage Runtime exception at 0x00400054: Cannot read directly from text segment!0x00400074' I think the line is supposed to load the value of memory location x200040054 to $t0. I tried manually entering the memory and register values and removing the first block of code to get a different program count when the line with the error executes, but get the same error.

li $t2, 0x0012b628
li $t3, 0x01234567
li $t4, 0xfedcba98
li $t5, 0xf0f0f0f0
sw $t2, 0x10000000
sw $t3, 0x10000004
sw $t5, 0x1000000C
li $a0, 0x000007de
li $t0, 0x52f123d6
li $t1, 0xffffffff 
li $s0, 0x10000000

        jal next
next :  lw $t0 , 0x20($31)  #line with error
        andi $t1 , $t0 , 0x07C0
        xor $t0 , $t0 , $t1
        lw $t1 , 0($s0)
        andi $t1 , $t1 , 0x07C0
        or $t0 , $t0 , $t1
        srl $t1 , $t1 , 6
        sw $t0 , 0x20($ra)
        sll $a0 , $a0 , 31

li $v0, 10
asked on Stack Overflow Sep 24, 2014 by Rohit N.

1 Answer


You are getting a runtime exception because the code you are running is trying to read and the write the text segment (the memory which holds the program code) and usually you cannot read/write those portions of memory at runtime.

The line of code that is giving you the exception is trying to put into register $t0 the contents of the instruction located 8 instructions ahead of $ra which at that moment should point to the location of instruction lw $t0 , 0x20($31) #line with error, that is the binary representation of instruction sll $a0 , $a0 , 31

Then, after some bit manipulation it tries to change the instruction sll $a0 , $a0 , 31 with some other instruction, apparently with sll $a0 , $a0 , 24

answered on Stack Overflow Sep 24, 2014 by gusbro

User contributions licensed under CC BY-SA 3.0