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

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.

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:

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.

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.

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.

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:

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.