How do I write an assembly program multiplies two operands, Data1 and Data2,  save result in Data3,Data1 16bits,Data2 8bits,8086 assembler.?

1 Answer

  • 5 months ago

    You didn't say how big data3 is, and  you didn't say whether inputs are signed or unsigned.  The unsigned version:

        mov al, data2

        mov ah, 0         ; change to "cbw" for signed numbers

        mul  data1        ; change to "imul" for signed numbers

        mov data3, ax  ; store the result (assumes data3 is 16 bits)

    If data3 is a dword (32 bits, 4 bytes), then replace the final mov with two instructions:

        mov word ptr data3, ax

        mov word ptr data3+2, dx

    That multiplies data2*data1 instead of data1*data2.  The results are the same, but it uses fewer instructions to widen the short number to fill ax before doing the 16-bit mul or imul.

Still have questions? Get answers by asking now.