Multiplication

@MJ · 2 min read
Created Date · 2024년 08월 14일 12:08
Last Update · 2024년 10월 20일 18:10

contents: 0-1. CA Intro

Multiplication

If a multiplicand and a multiplier have m and n digits, the product has at most m + n digits

  • MIPS-based computers use 32-bit word for the arithmetic operations

  • The product in MIPS-based computers has at most 64 digits


Optimized version of the multiplication HW

  • 32-bit multiplicand register / ALU

  • 64-bit product register (multiplier shares a register with product)

    - HI: most significant 32 bits

    - LO: least significant 32 bits

    - Actually, there is one more bit in the left of the product register to hold the carry out of the adder

01 2.jpg
01 2.jpg


Settings

  • 0 is stored in the left half of the product register

  • The multiplier value is loaded into the right half of the product register

  • The multiplicand value is loaded into the multiplicand register


Multiplication Algorithm

02 2.jpg
02 2.jpg

Example

When N = 4 (4-bit ALU / multiplicand, 8-bit product), 2×32 \times 3

  • should be repeated as many bits as it is

03 1.jpg
03 1.jpg

Signed multiplication

Do multiplication after converting both multiplicand & multiplier to positives

  • For 31 iterations (except a sign bit)

  • After the multiplication, negate the result (if it is required)

Better solution: Booth's Algorithm

  • Supports multiplication of two's complement signed numbers in a more efficient way

  • Requires almost same hardware with the multiplication of unsigned numbers


Instructions

  • mult rs, rt / multu rs, rt (rs: multiplicand, rt: multiplier)

    - The result (product) is stored in HI / LO

04 1.jpg
04 1.jpg

  • mfhi rd / mflo rd

    - Move from HI / LO to rd

05 1.jpg
05 1.jpg

Example: mult $t0, $ t1

  • $t0 (multiplicand) is used as the Multiplicand register

  • Initially, the value in $t1 (multiplier) is loaded into LO register

  • Then, do the multiplication and store the 64-bit product to HI and LO registers