How define a temprary register/variable in x86 assembly? help needed

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 2
Reputation: ada829 is an unknown quantity at this point 
Solved Threads: 0
ada829 ada829 is offline Offline
Newbie Poster

How define a temprary register/variable in x86 assembly? help needed

 
0
  #1
May 2nd, 2008
Hi,

I am trying to do some sort of intrumentation inside the assembly code generated by the pentium machine. Particualrly, I need to use some temporary register which can store some value. since x86 has only 6 general purpose registers I am not sure which ones are reused and cannot be used as temporary storage. Please help me if anyone knows a way to solve this.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 150
Reputation: sDJh is an unknown quantity at this point 
Solved Threads: 13
sDJh sDJh is offline Offline
Junior Poster

Re: How define a temprary register/variable in x86 assembly? help needed

 
0
  #2
May 2nd, 2008
You can use any of these registers. The data is stored until you/your generated code that overwrites or chages it by some functionst. eg.
  1. MOV EAX,100h ;<- stores 100h in EAX
  2. some code here
  3. MOV EAX,0 ;<-clears the register
  4. XOR EAX,EAX ;<- clears the register as but faster
  5. ADD EAX,EBX ;<- adds the value of EBX to EAX

If you don't know what the generated code is doing, then you better store it in memory. Define a place to store and then change it:
  1. myval DD 100h ;<- at that position 100h is stored
  2. MOV EAX,[myval] ;<- now EAX has the same value
  3. MOV EAX,200h ;<- new value for EAX...
  4. MOV [myval],EAX ;<- .. that can be saved in myval.
Whereas myval can be defined anywhere you want apart directly in the code. The best is, you put it at the end (which should be done my the code-generator as well).
In this case you can always be sure, that the variable won't be overwritten.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 2
Reputation: ada829 is an unknown quantity at this point 
Solved Threads: 0
ada829 ada829 is offline Offline
Newbie Poster

Re: How define a temprary register/variable in x86 assembly? help needed

 
0
  #3
May 3rd, 2008
Thanks a lot for the post! I appreciate it. In this case I don't what the assembly is doing but I still need an extra register for temporary storage and scratchpad. I also found another way of doing this . If the code is compiled using -fomit-frame-pointer the %ebp register is in most cases unused and hence it can be used as a temp register. However both these methods have high performance overhead!




Originally Posted by sDJh View Post
You can use any of these registers. The data is stored until you/your generated code that overwrites or chages it by some functionst. eg.
  1. MOV EAX,100h ;<- stores 100h in EAX
  2. some code here
  3. MOV EAX,0 ;<-clears the register
  4. XOR EAX,EAX ;<- clears the register as but faster
  5. ADD EAX,EBX ;<- adds the value of EBX to EAX

If you don't know what the generated code is doing, then you better store it in memory. Define a place to store and then change it:
  1. myval DD 100h ;<- at that position 100h is stored
  2. MOV EAX,[myval] ;<- now EAX has the same value
  3. MOV EAX,200h ;<- new value for EAX...
  4. MOV [myval],EAX ;<- .. that can be saved in myval.
Whereas myval can be defined anywhere you want apart directly in the code. The best is, you put it at the end (which should be done my the code-generator as well).
In this case you can always be sure, that the variable won't be overwritten.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC