| | |
How define a temprary register/variable in x86 assembly? help needed
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 2
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Aug 2005
Posts: 150
Reputation:
Solved Threads: 13
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.
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:
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.
Assembly Syntax (Toggle Plain Text)
MOV EAX,100h ;<- stores 100h in EAX some code here MOV EAX,0 ;<-clears the register XOR EAX,EAX ;<- clears the register as but faster 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:
Assembly Syntax (Toggle Plain Text)
myval DD 100h ;<- at that position 100h is stored MOV EAX,[myval] ;<- now EAX has the same value MOV EAX,200h ;<- new value for EAX... MOV [myval],EAX ;<- .. that can be saved in myval.
In this case you can always be sure, that the variable won't be overwritten.
•
•
Join Date: May 2008
Posts: 2
Reputation:
Solved Threads: 0
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!
•
•
•
•
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.
Assembly Syntax (Toggle Plain Text)
MOV EAX,100h ;<- stores 100h in EAX some code here MOV EAX,0 ;<-clears the register XOR EAX,EAX ;<- clears the register as but faster 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:
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).Assembly Syntax (Toggle Plain Text)
myval DD 100h ;<- at that position 100h is stored MOV EAX,[myval] ;<- now EAX has the same value MOV EAX,200h ;<- new value for EAX... MOV [myval],EAX ;<- .. that can be saved in myval.
In this case you can always be sure, that the variable won't be overwritten.
![]() |
Other Threads in the Assembly Forum
- Previous Thread: Converting Functions
- Next Thread: Convert C code to Assembly code
| Thread Tools | Search this Thread |





