-2

I am trying to write an assembly code that could compute the product of two integers from the keyboard without using an multiplication operators. I am completely stuck, I am new to assembly language and Linux/C so any advice is appreciated.

Maybe by using a loop of some sort?

hales1915
  • 9
  • 1
  • x86 asm duplicate: an answer on [How can I perform multiplication without the '\*' operator?](https://stackoverflow.com/a/2069674). I assume you're using Linux on an x86 CPU? It runs on many architectures, all of which have different assembly languages. – Peter Cordes Jun 17 '20 at 21:35

1 Answers1

0

You want to use shifting and addition to do this.

Lets say that you are trying to multiply 3 * 3, and we had a 4 bit register.

In binary: 0011 * 0011

if we encounter a 1 we shift right by the value of the index where we found the 1, if we have a zero we don't do anything:

0011

first we have 1, at location 0, so we add the number to an empty register without shifting: we have 0011 so far

then we have another 1, at location 1, we shift the original number 0110, and add it to the previous value 0011

0011 + 0110 => 1001 ; since we have all 0's after we are done

You need to iterate over the bits of one of the value that you will be multiplying and everytime that you have a 1 apply a shift that will correspond to its location.

bhristov
  • 3,137
  • 2
  • 10
  • 26
  • thank you, this helps a bit...my next question would be how do you actually do that as a code? I also read using jump loops can be helpful but I am not sure – hales1915 Jun 17 '20 at 21:12