View Single Post
  #2  
Old 03-01-2015, 21:11
mcp mcp is offline
Friend
 
Join Date: Dec 2011
Posts: 73
Rept. Given: 4
Rept. Rcvd 12 Times in 11 Posts
Thanks Given: 7
Thanks Rcvd at 47 Times in 35 Posts
mcp Reputation: 12
Not sure I really understand your question.
It seems you're asking on how to reconstruct the original register based instructions? That is not possible, as that information is destroyed.

For example, given that stack based VM, you cannot distinguish

Code:
mov eax,ebx
mov ecx,eax
mov edx,ecx
from

Code:
mov ebx,eax
mov edx,ebx
mov ecx,edx
What you can do however, is what in compiler construction is called "register allocation". It basically means, that you start with arbitrarily many variables (in this case your stack variables from the stack machine) and find an allocation of assigning these variables to registers while at the same time trying to minimize the amount of register spills. Even a greedy algorithm should work sufficiently well in that case.
OTOT, for what reason do you actually want to dos this anyway? Re-assemble VM code?
Reply With Quote
The Following User Gave Reputation+1 to mcp For This Useful Post:
Conquest (03-01-2015)