Tuts 4 You

Problem trying to replicate the assembly code

Recommended Posts

`movzx ecx,byte ptr [ebp+8]mov eax,055555556himul ecx`

I can understand what those instructions are doing. For instance if ecx takes the letter 'x', the registers would contain the following:

EAX: 0x50

ECX: 0x78

EDX: 0x28

Because 55555556 x 78 = 28000050, the high part goes to EAX and the low part goes to EDX.

What I cant understand is how do I replicate this using C or C++, I tried to make a function that multiplies some hex number with 55555556 and keep the high/low byte on another variable. But RE that program doesn't produces the same results as those assembly instructions.

Can anyone explain me how to translate those instructions into some HLL?

Edited by teerryn

It's an optimized way to do integer division

`b = a / 3;`

where a is input value (in ecx) and b is the result (in edx);

• 1

That's it, thanks so much for the help, guess this kind of knowledge only comes with experience and work.

Division by multiplication: http://research.swtch.com/divmult

Just as an aside, the disassembly is using hexadecimal but in your post you referred to multiplying by what appears to be a decimal number, this will produce incorrect results also if you are translating assembler to code directly:

55555556 != 0x55555556

55555556 * 10 = 0x211D1AE8 or 555555560

0x55555556 * 10 = 0x35555555C or 14316557660

HR,

Ghandi

Edited by ghandi
• 1