The Multiply Halfword instruction performs 2’s complement binary multiplication.  Operand 1 names a single register (even or odd) which will contain the multiplicand.  Operand 2 is the name of a halfword in memory containing the multiplier.  After the multiplication, the product is left in Operand 1, destroying the multiplicand.  It is possible to generate a product that will not fit in a single register, but an overflow will not be indicated.  Leftmost bits in the product could be truncated to 32 bits in Operand 1.  The programmer must be aware of the limits of the data being processed and protect against the possibilities of overflows.  Select a fullword multiplication (M) if you are unsure of your data.

 

    Assume you want to multiply a fullword field called “COST” by a halfword field called “NOITEMS”.   The following code would accomplish this task and leave the product in register 5.

 

                        L    R5,COST

                        MH   R5,NOITEMS

                  

        Some Unrelated Multiply Halfword Instructions

 

       L    R6,=F’100’   MULTIPLICAND GOES IN ANY REGISTER

       MH   R6,=F’10     R6 = X’000003E8’ = 1000

 

       L    R7,=F’3’     MULTIPLICAND GOES IN ANY REGISTER

       MH   R7,=F’-2’    R7 = X’FFFFFFFA’ = -6

 

       L    R3,=F’8’     MULTIPLICAND GOES IN ANY REGISTER

       MH   R3,=F’2’     R3 = X’00000010’ = 16    

 

       L    R3,=F’8’     MULTIPLICAND GOES IN ANY REGISTER

       MH   R3,=F’0’     R3 = X’00000000’ = 0

 

       L    R4,=X’7FFFFFFF’  LARGEST POSITIVE NUMBER IN A SINGLE REG.

       MH   R4,=F’2’     MULTIPLYING BY 2 CAUSES OVERFLOW

                         R4 = X’FFFFFFFE’ = -2   INCORRECT RESULT

 

 

 

 

 

 

 

 

 

1)  Know your data!  To use MH, one of the operands must be small enough to fit in a halfword.  This range is -32768 to +32,767.  The product of the multiplication must fit in a single register where the range of integers is -2,147,483,648 to +2,147,483,647. In many cases, the product of a multiplication will fit in a single register.   If you have any doubts about the size of a generated product, use M instead of MH.