Pages

Search in This Blog

Sunday 15 January 2012

multiplication instructions


MULTIPLICATION INSTRUCTIONS

  • MUL Instruction - Multiply unsigned bytes or words-MUL source
MUL Instruction - This instruction multiplies an unsigned multiplication of the accumulator by the operand specified by op. The size of op may be a register or memory operand .
Syntax: MUL op

Example:
                                             ;AL = 21h (33 decimal),BL = A1h(161 decimal )
MUL BL                                   ;AX =14C1h (5313 decimal) since AH≠0, CF and OF will set to 1.
MUL BH                                  ; AL times BH, result in AX
MUL CX                                  ;AX times CX, result high word in DX,low word in AX.
  • IMUL Instruction - Multiply signed number-IMUL source
This instruction performs a signed multiplication.There are two types of syntax for this instruction. They are:
IMUL op                               ;In this form the accumulator is the multiplicand and op is the multiplier. op may be a register or a memory operand.
IMUL op1, op2                      ;In this form op1 is always be a register operand and op2 may be a register or a memory operand.

Example:
IMUL BH                               ;Signed byte in AL times multiplied by signed byte in BH and result in AX .

Example:
                                          ; 69 * 14
                                          ; AL = 01000101 = 69 decimal
                                          ; BL = 00001110 = 14 decimal
IMUL BL                               ;AX = 03C6H = + 966 decimal ,MSB = 0 because positive result , - 28 * 59
                                          ; AL = 11100100 = - 28 decimal ,BL = 00001110 = 14 decimal
IMUL BL                               ;AX = F98Ch = - 1652 decimal, MSB = 1 because negative result

  • AAM Instruction - ASCII adjust after Multiplication
AAM Instruction - AAM converts the result of the multiplication of two valid unpacked BCD digits into a valid 2-digit unpacked BCD number and takes AX as an implicit operand. To give a valid result the digits that have been multiplied must be in the range of 0 – 9 and the result should have been placed in the AX register. Because both operands of multiply are required to be 9 or less, the result must be less than 81 and thus is completely contained in AL. AAM unpacks the result by dividing AX by 10, placing the quotient (MSD) in AH and the remainder (LSD) in AL.

Example:
MOV AL, 5
MOV BL, 7
MUL BL                       ;Multiply AL by BL , result in AX
AAM                           ;After AAM, AX =0305h (BCD 35)

No comments:

Post a Comment