teerryn Posted August 15, 2012 Posted August 15, 2012 (edited) 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, 2012 by teerryn
kao Posted August 15, 2012 Posted August 15, 2012 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); 1
teerryn Posted August 15, 2012 Author Posted August 15, 2012 That's it, thanks so much for the help, guess this kind of knowledge only comes with experience and work.
ghandi Posted August 16, 2012 Posted August 16, 2012 (edited) 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, 2012 by ghandi 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now