|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Mips, self modifying code
hi, i need help with self modifying code.
the assignment is to actually write a calculator program. it basically takes some input binary,decimal,hex and does 4 operations +,-,*,/ but there is a special case where when the result is 7 the program will modify itself so that from then on entering addition will instead give the logical AND of the two operands. I dont know anything about self modification. |
|
#2
|
|||
|
|||
|
I don't know any MIPS, but the idea is to write to the part of memory where the code itself resides. It's easier if the modifications don't change the size of the code. You still need to know the exact memory address of the instruction(s) you want to change, but perhaps the assembler will compute this for you.
Here's a quick example in pseudo-assembly: suppose you have the following instruction that adds register reg1 to reg2: Code:
the_instruction:
add reg2, reg1
You want to change this to an AND operation: Code:
and reg2, reg1 For simplicity, let's assume registers and instructions are the same size in bits, say 32 bits. (This is often not the case, and I don't know about MIPS specifically.) You need to put your replacement instruction somewhere: Code:
replacement_instruction:
and reg2, reg1
Code:
load reg1, [replacement_instruction]
store [the_instruction], reg1
|
|
#3
|
|||
|
|||
|
thank you very much
. stupid self modification was frying my brain lol i did everything but that *sigh* |
|
#4
|
|||
|
|||
|
omg after spending hours on this from reading to book to surfing i couldn't do it!!!
but your explanation was all i needed.. thank you very much !!!!!!!!!!!!!!!!!I LOVE YOU!!!!!!!!! |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Mips, self modifying code |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|