In: Computer Science
Open selfmodifying.asm in MARS. Before running the code, predict: what will be the result in register $s0when this program is finished running? Now when you run the program, you will see an error: “Cannot read directly from text segment!”. To allow code to read and write the text segment, check Settings | “Self-modifying code”. Now click run again.
a) Explain the result in register $s0when this program is finished running. In order to understand what is going on, we suggest...
•Step through the program line by line, paying careful attention to the Text Segment and registers.
•Work it out on paper
b) Why would an operating system, which is in charge of running the user’s programs, need to be able to modify the Text Segment?
c) While operating systems can modify the Text Segment, for security purposes they disallow user programs from modifying the Text Segment. Explain.
selfmodifying.asm:
la $t2, wow
lw $t1, 0($t2)
addiu $t1, $t1, 0xFED
sw $t1, 0($t2)
wow: addiu $s0, $zero, 1
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
after executing the code in self mode . Text sagment will be as below.
and the content of s0 will be
Explanation.
User program may be need to change the text sagment based on some condition and to save lot of space in case of large application.
But user code is not allowed to change the text sagment , Becuase on alternation they can read system file and can change in it as well.