I have been having problems even initiating the solution for the problem. I have tried considering the multiplication is repeated addition algorithm but whatever algorithm I consider, I seem to be fixated over a single issue- the max register size in 8086 is 16-bit.
data segment
num1 dw 0102h,0304h,0506h,0708h
num2 dw 0102h,0304h
res dw ?,?,?,?,?,?
data ends
code segment
assume CS:CODE, DS:DATA
start:
mov ax,DATA
mov DS,ax
..........fill code..........
At this point I am stuck. Even a slight hint of code or just the algorithm would be appreciated.
For multiplying a 64-bit number by a 32-bit number with a 16-bit CPU:
Step 1: Assume the numbers are in "base 65536". For example, a 64-bit number has 16 digits in hex (e.g.
0x0123456789ABCDEF) and would have 4 digits in "base 65536" (e.g.{0123}{4567}{89AB}{CDEF}); and in the same way a 32-bit number would have 2 digits in "base 65536".Step 2: To multiply a pair of numbers, multiply each digit from the first number with each digit from the second number, and add this into the right place in the result. The right place depends on the position of each digit in the original numbers. For example (in decimal) for 90 * 30 you'd do "9*3 = 27" and put it in the "hundreds" place (e.g. 2700) because there was one digit to the right in the first number plus another digit to the right in the second number, and that means it needs to go where there's 2 digits to the right in the result.
Example:
Note that 8086 has a "16 bit multiplied by 16 bit = 32-bit result" instruction (
MUL); and addition can be done 16 bits at a time by using oneADDinstruction followed by however manyADCinstructions you need.Also note that you can avoid some additions by merging. For example:
Of course, because it doesn't matter which order you do the multiplication of pairs of ("base 65536") digits; you can do all the multiplications in the optimum order for merging.
For the final code (with merging); you'd end up with 8
MULinstructions, 3ADDinstructions and about 7ADCinstructions. I'm too lazy to write the code. ;)