Domanda

I know there are some posts talking about translate assembly to C, but basically they all aims at how to get a Human Readable C source code.

So what I want to achieve is the translation process with stack implemented on heap.

I don't need to make the code easy to read, only translate into a legal c source code or even pseudo code (if directly translate into c source code is too hard),

but in this relatively easily task(not easy at all), I want to implement the stack on heap, just like ML and Scheme compiler have done..

Could anyone give me some guide and instructions on this stuff?

The experiment environment should be on x86, and assembly is generated from

gcc -S source

suppose we have the original c source code in this task, could it help?

È stato utile?

Soluzione

Assuming x86/x64 here...

The stack pointer is tracked by ESP (32bit) or RSP (64bit) registers. You can insert a mov ESP, ADDRESS instruction into the ASM and change the stack to your preferred location. You'll need to store ESP/RSP on the new stack first because you need it for later.

Immediately after setting ESP/RSP call main() (or any other C function for that matter) in the C program.

After function returns, restore ESP/RSP to it's original value.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top