I already know about LEA, that does not help. I want to understand HOW to multiply by an odd number using the operands shl, shr, mov, add , and sub. So far, I've been reading Andrew Tanenbaum's 6th edi Struct Comp Org. It has not helped explain why and how to do such a thing.
Asked
Active
Viewed 161 times
0
-
2It's not clear what you need help understanding. x * 3 == (x << 1) + x. x * 7 == (x << 3) - x. etc. – Michael Feb 02 '16 at 19:46
-
It doesn't really matter whether it's odd or not. Trivially, if you can do it for even numbers, just add the original number once and you got your odd. – Jester Feb 02 '16 at 19:54
-
Well, for my level it does. I am beginning to learn assembly and having a thorough explanation on how to perform operation likes these are pretty important. – archon263 Feb 02 '16 at 19:57
-
Oh, it is a duplicate. Except that I couldn't understand what he was doing. I now understand that to multiply in assembly, you would represent your x-val in binary. You would shift the values by order of 2^n, then add or subtract the register ( which contains the x-val) until it matches the value you want to multiply by in binary. – archon263 Feb 02 '16 at 20:04
-
So I understand how to multiply 5 by 13 mov eax , 5 mov ebx , eax shl eax , 4 // gives us 16 *eax shr ebx, 1 // gives us 3*eax sub eax, ebx // gives us (16-3)*eax ::: end result : we get 13 * eax = 13 *5. That was the explanation I was looking for. – archon263 Feb 02 '16 at 20:06