Posted August 15, 201213 yr 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? Thank in advance for your help Edited August 15, 201213 yr by teerryn
August 15, 201213 yr It's an optimized way to do integer divisionb = a / 3;where a is input value (in ecx) and b is the result (in edx);
August 15, 201213 yr Author That's it, thanks so much for the help, guess this kind of knowledge only comes with experience and work.
August 16, 201213 yr Division by multiplication: http://research.swtch.com/divmultJust 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 != 0x5555555655555556 * 10 = 0x211D1AE8 or 5555555600x55555556 * 10 = 0x35555555C or 14316557660HR,Ghandi Edited August 16, 201213 yr by ghandi
Create an account or sign in to comment