Page 1 of 1

mips, self modifying code

Posted: Thu Sep 18, 2008 9:14 am
by ramaz
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.

Posted: Thu Sep 18, 2008 11:11 am
by J.F.
So you want us to do your homework for you?

I'll give this much help - go download a MIPS manual and you'll find the assembly language. You're basically being asked to do some simple machine language commands - replacing the add opcode with an and opcode.

Posted: Thu Sep 18, 2008 12:51 pm
by ramaz
no, im sorry i worded it wrong. i was able to do everything. except the self modification. i had no clue how to do it

Posted: Thu Sep 18, 2008 1:11 pm
by J.F.
Okay, that's better. :)

Look up the opcodes you'll need (in the manual I mentioned). Look at the hex values... you'll need to store the code over top of the old code, flush the data cache to make sure the value is written to memory, then invalidate the code cache to make sure the CPU fetches the new code from memory instead of the cache.