Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 17th, 2008, 05:57 PM
ramaz ramaz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 3 ramaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 46 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old September 17th, 2008, 09:29 PM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,624 Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level)Lux Perpetua User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 5 h 17 m 3 sec
Reputation Power: 784
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
Put it somewhere where it won't be executed, since it isn't going to be part of the program initially. Now you write the replacement instruction to memory to replace the initial one:
Code:
    load reg1, [replacement_instruction]
    store [the_instruction], reg1
There are several things that can make this more complicated, some of which I have indicated, but I only wanted to give you the gist of it, since you said you didn't know anything. Good luck!

Reply With Quote
  #3  
Old September 17th, 2008, 09:54 PM
ramaz ramaz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 3 ramaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 46 sec
Reputation Power: 0
thank you very much . stupid self modification was frying my brain lol i did everything but that *sigh*

Reply With Quote
  #4  
Old September 17th, 2008, 10:47 PM
ramaz ramaz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 3 ramaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 46 sec
Reputation Power: 0
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!!!!!!!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Mips, self modifying code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT