8086 Integer Multiplication Instructions – Assembly Language Programming

In this tutorial, we will see multiplication instructions supported by 8086 microprocessor such as signed, unsigned multiplication instructions. In the last tutorial, we have discussed 8086 addition and subtraction instructions.

Previous Tutorials in the series are : 8086 Data Transfer Instructions , 8086 Integer Arithmetic Instructions , 8086 Microprocessor Addressing Modes

8086 Multiplication Instructions

The multiplication instructions include:

  • MUL
  • IMUL
  • AAM

8086 Unsgined Multiplication Instruction (MUL)

The MUL instruction deals with the multiplication of two unsigned numbers. There are types of multiplication depending on the number of bits:

  • Byte with byte
  • Word with Word
  • Byte with word

Byte with Byte multiplication: In this multiplication, one operand resides in an AL register and the other one is source. Source can be a register or memory address.

For example:

MUL BL      ;Multiply data in Bl with AL
MUL 10[CL]   ;Multiply data stored at offset address CL+10 with data in AL

Assembly Code Example 1

Suppose you want to multiply 35 with 15. The multiplication of 35 and 15 gives 525 whose hexadecimal value is 20D. The result is stored in AX register.

ORG 100h
.CODE
MOV AL, 35
MOV BH, 15
MUL BH
RET

Output:

8086 MUL instruction multiplication assembly code example 1

Word with Word Multiplication

In this multiplication, one operand is loaded in AX register and the source should be a 16-bit register or a memory address. The two words of 16-bits on multiplication can produce a 32-bit word. So, in that case, the lower bytes of word are stored in AX register and higher bytes in DX register.

Assembly Code Example

ORG 100h
.MODEL SMALL
.DATA
VAR_1 DW  12DAH
VAR_2 DW  3F24H
.CODE 
MOV AX, VAR_1
MOV BX, VAR_2
MUL BX
RET

The address of VAR_2 is 0004h. You can also check the address by “LEA BX, VAR_2” or “MOV BX, OFFSET VAR_2”. Both commands give address in BX register. The “MUL 20[VAR_2]” instruction multiply the content at memory address 0118h (0004h +14h) with AX i.e., 90C3 x 12DA gives AA8 FC0E. The FC0E goes to AX register and DX stores AA8. We have reserved eight bytes to RES offset. Using MOV command, the final result is stored in these reserved bytes.

8086 MUL instruction multiplication assembly code example 2

Byte with Word Multiplication

It is similar to the word with word multiplication. Only the AH register is set to zero and AL is loaded with a byte operand. The result gets stored at DX and AX registers.

Assembly Code Example

Let us assume the code in Example 2. Only set AH to zero. You can do this either by subtracting AH from AH or by loading AH with 0.

ORG 100h
.MODEL SMALL
.DATA
VAR_1 DW  12DAH
VAR_2 DW  3F24H 
RES   DW  2 DUP(?) ;Reserves 8 bytes of uninitilized data space to RES offset
.CODE   
MOV AX,VAR_1       ;Load 1st opernd to AX
SUB AH,AH    
MUL 20[VAR_2]      ;Load 2nd operand from effective address 20+VAR_2 
                   ;multiply it with AX
MOV RES,AX         ;Copy AX in lower 2 bytes of RES
MOV RES+2,DX       ;Copy DX in upper 2 bytes of RES
RET

Output

Now in this case the data at offset address 20[VAR_2] is 0108h so the operands are DA and 0108. The multiplication of two operands give E0D0 which is stored to AX register.

8086 MUL instruction multiplication assembly code example 3

8086 Singed Multiplication Instruction (IMUL)

The IMUL instruction allows the multiplication of two signed operands. The operands can be positive or negative. When the operand is a byte, it is multiplied with AL register and when it is a word, it is multiplied with AX register. The operation of MUL and IMUL instructions are same. The only difference between two is one deals with the multiplication of unsigned numbers and the other deals with signed operands.

If the product of multiplier and multiplicand produce result that fits into the destination register DX and AX with some of the bits left unused. Then these unused bits are filled with the copies of signed bit and clear CF and OF flags to zero.

Example Assembly Code

ORG 100h
.MODEL SMALL
.CODE   
MOV AL, 2AH       ;Load 1st operand to AX
MOV BX, -26CH     ;Load 2nd operand in BX
IMUL BX
RET

Output

The multiplication gives a negative result that’s why higher bits in DX are FFFF.

8086 IMUL instruction signed multiplication assembly code example 1

IMUL Assembly Code Example 2

If only parts of the destination registers are filled like in 16-bit multiplication, one AH bit is unfilled or in 32-bit multiplcation parts of DX or DH are left unfilled, then both CF and OF flags set to 1.

ORG 100h
.MODEL SMALL
.CODE   
MOV AX, 2A45H     ;Load 1st operand to AX
MOV BX, -26CH     ;Load 2nd operand in BX
IMUL BX
RET

Output

8086 IMUL instruction signed multiplication assembly code example 2

8086 ASCII Adjust Multiplication Instruction

The AAM is a mnemonic for “ASCII Adjust Multiplication”. It corrects or adjusts the product of two unpacked BCD numbers into a correct unpacked BCD number. This conversion of result to BCD number is done by AAM instruction. In the case of multiplication of two ASCII numbers, we need to mask the upper 4 bits of both operands in order to get 1 BCD digit per byte.

The AAM instruction works on the content of the AL register and converts it to a BCD number. Therefore, the product of two unpacked BCD numbers should be stored in the AL register. Multiply BCD numbers using the MUL command. Store the product in the AX register. Then, call AAM instruction. AAM instruction divides the data in AL by 10. After that, it stores the quotient in AH and the remainder in AL. AAM sets SF, ZF, and AF flags according to the result.

Example Assembly Code

Consider an example in which two numbers 7 and 9 are multiplied. The product is 63 with hexadecimal value of 3F. AAM instruction divide the product by 10 which gives quotient of 06 and 03 as a remainder. You can see in the register window of output, the AH has 06 and AL has 03.

ORG 100h
.MODEL SMALL
.CODE   
MOV AX, 036H     ;Load 1st operand in AX  
MOV DX, 032H     ;Load 2nd operand in DX
MUL DX
AAM
RET

Output

8086 AMM instruction multiplication assembly code example

Leave a Comment

five × 2 =