#1
|
|||
|
|||
Stack Machine to Register Machine
1st of all i want to state that my question may be invalid in sense that the documents i am asking for doesnt exists at all. SO please correct me if you think so .
Can someone point to some documents on converting assembly from stack based architectures to register based architecture . Currently i am working on vmp vm which converts the x86 machine to stack based machines by replacing register locations intermediate stack locations . I have studied compiler documents on stack machines but so far i havent found any documents which guides me to convert the machine structure from one to another. Biggest issue i am facing is loss of intermediate register data . what i mean is right side registers are always converted into stack locations and then dont always link together. If we have something like this Code:
mov ebx,eax mov ebx,ecx Code:
load [sr1],[mem1] store [mem2],[sr1] load [sr1],[mem3] store [mem4],[sr1] Code:
sr = stack register mem = stack memory , i.e. scratch memory in stack mem1 = mapped as eax mem2 = intermediate memory which was suppose to be ebx mem3 = mapped as ecx mem4 = mapped in output as ebx Code:
mov eax,ebx mov ecx,eax mov edx,ecx Code:
//sample code MOV EAX,EBX MOV ECX,EAX MOV EDX,ECX MOV EDX,EBP MOV EAX,0x539 MOV EAX,EDX //transformed stack based machine code loc=00000030 (EBX) -> [sr1] [sr1] -> loc=00000000 (missing) loc=00000000 -> [sr1] [sr1] -> loc=00000004(ECX) loc=00000004(ECX) -> [sr1] [sr1] -> loc=00000008 (missing) loc=00000038(EBP) -> [sr1] const 539 -> [sr2] [sr2] -> loc=00000020(missing) [sr1] -> loc=0000003C(EDX) loc=0000003C(EDX) -> [sr1] [sr1] -> loc=0000001C(EAX) You will see several intermediate stack locations cant be deducted and it is not safe to allocate any register to them randomly as this may corrupt the assembly . i am looking for expert advice in this area(specially people with compiler design knowledge) about how to map registers and what kind of knowledge do i need to solve this. Last edited by mr.exodia; 03-01-2015 at 18:15. Reason: fixed |
The Following User Gave Reputation+1 to Conquest For This Useful Post: | ||
ahmadmansoor (03-01-2015) |
#2
|
|||
|
|||
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 Code:
mov ebx,eax mov edx,ebx mov ecx,edx OTOT, for what reason do you actually want to dos this anyway? Re-assemble VM code? |
The Following User Gave Reputation+1 to mcp For This Useful Post: | ||
Conquest (03-01-2015) |
#3
|
|||
|
|||
Quote:
Thanks for your info anyway. I will look forward to have advice from more people involved in this area. |
#4
|
|||
|
|||
Also see this discussion on hackernews on stack vs register machines and the corresponding article.
|
#5
|
|||
|
|||
Quote:
PS:couldnt give a thanks for the help for not being a family member. Last edited by Conquest; 03-07-2015 at 23:11. Reason: Added thanks |
#6
|
|||
|
|||
Also see MS' JIT compiler which is now open source: https://github.com/dotnet/coreclr
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Sentinel SHK Virtual Machine | phroyt | General Discussion | 4 | 07-05-2022 23:51 |
You do not have a Codewizard for C++ 4.3 license for this machine | matrowang | General Discussion | 0 | 05-10-2004 15:19 |
Softice rebooting my machine | Mok | General Discussion | 4 | 09-07-2003 00:01 |