I need assistance decompiling the following from ASM to pseudo C.

Code 1
mov edx, Var1       # Move Var1 to edx
mov ecx, Var2       # Move Var2 to ecx
mov eax, edx        # Move EDX (Var1) to EAX
imul ecx            # Multiply EAX (Var1) by ECX (Var2). Store result into EDX:EAX
mov edx, eax        # Move EAX to EDX
imul edx, eax       # Multiply EDX and EAX, store result into EDX
mov Var3, ecx       # Move ECX into Var3

I commented the ASM and deduced it results in Var3 = Var2. But what would the C code look like?

Code 2
    mov dword ptr [esi], 1
    xor edx, edx
    mov [ebx], edx
    jmp short loc_4012F1

    mov ecx, [esi]
    imul ecx, [esi]
    mov [esi], ecx
    inc dword ptr [ebx]

    cmp dword ptr [ebx], 8
    jl short loc_4012E8

For this second code, I'm thinking something like,

for (int i = 0; i > 8; i++){
int a = 8;

int b = 9;

int c = a * b;

Appreciate any help

1 Answer 1


Simple solution d123 use IDA PRO with Hex-Rays Decompiler, it produces very good results for simple assembly codes like this

I assembled your code line by line.

assembly code image

Then Pressed F5 key and bam got this code below!

_DWORD *a1@<ebx>;
_DWORD *a2@<esi>;
  *a2 = 1;
  for ( *a1 = 0; *a1 < 8; ++*a1 )
    *a2 *= *a2;

it can compile too if you rename _DWORD to unsigned int and remove @<ebx> and @<esi> these are just to show what a1 and a2 means

  • Expensive solution is more like it. I've been a customer of IDA Pro for well over a decade and participated in an early beta of the Hex-Rays decompiler plugin, but since it let me more astray than it helped, I decided to not buy the plugin (and pay for the upkeep of maintenance every year). Of course others simply pirate the software, but as a paying customer I am a bit biased against that, even if it sometimes would be more convenient.
    – 0xC0000022L
    Jul 5, 2018 at 13:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.