Multiplication and Division

 

Multiplication

The M (RX) and MR (RR) instructions perform multiplication of binary fullword operands. The multiply instructions use an even-odd register pair to hold the first operand and the product. An even-odd register pair is a pair of consecutive registers that starts with an even register, such as registers 2 and 3, registers 6 and 7, or registers 10 and 11.

To perform a multiplication, the multiplicand is loaded into the odd register of the even-odd pair. The even register is the one referenced in the multiply instruction. After the multiplication, the product is in the even-odd pair. If you know the product will fit in one register, then it will be in the odd register of the pair.

Division

The D (RX) and DR (RR) instructions perform division of binary fullword operands. The division instructions use an even-odd register pair to hold the first operand, the quotient, and the remainder.

To perform a division, the dividend is loaded into the odd register of the even-odd pair. The even register must also be initialized; if the dividend is positive, the even register must be set to binary zeros, and if the dividend is negative, the even register must be set to binary ones. The standard way to do this is to load the dividend and then multiply by one to make the dividend an 8 byte number. The even register is the one referenced in the divide instruction. After the division, the odd register contains the quotient and the even register contains the remainder.

Examples

C++ Version Assembler Version
A = B * C;   L    5,B
  M    4,C
  ST   5,A
A = B * C;   L    7,B
  L    11,C
  MR   6,11
  ST   7,A
A = B / C;   L    7,B
  M    6,=F'1'
  D    6,C
  ST   7,A
A = B / C;   L    11,B
  L    3,C
  M    10,=F'1'
  DR   10,3
  ST   11,A
A = B % C;   L    3,B
  M    2,=F'1'
  D    2,C
  ST   2,A
A = B % C;   L    9,B
  L    7,C
  M    8,=F'1'
  DR   8,7
  ST   8,A

Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2003