So I'm attempting to implement a multiplier in an assembly language program using the shift and add algorithm. I don't have a left shift instruction available in this ISA, but I do understand that adding a number to itself will shift the number left by one.
Let's say I want to multiply 5 * 15, which would be 101
multiplied by 1111
. I understand that I need to multiply 5 by each partial bit in 15, but I'm confused on how I can access/work with these partial bits. From right to left, I multiply 1
by 101
to get 101, add a placeholder to shift left, and continue with each successive bit, getting 1010
, 10100
, and 101000
. Then I add up these numbers to get 1001011
which is 75, the correct answer.
So, how would I be able to do this in assembly? I'm quite confused. Thanks!