mul, mult, and multu Instructions


All MIPS multiply instructions ignore overflow, so it is up to the software to check to see if the product is too big to fit in 32 bits. There is no overflow if hi is 0 for multu or the replicated sign of lo for mult.
mfhi rd         # move from hi
mflo rd         # move from lo
Move the hi (lo) register to register rd. The instruction mfhi can be used to transfer hi to a general-purpose register to test for overflow.
mul mulu (no overflow) mult
  .text
  li    $t0, -11
  mul   $a0, $t0, 12
  li    $v0, 1
  syscall
  .text
  li    $t0, -11
  mulu  $a0, $t0, 12
  li    $v0, 1
  syscall
  .text
  li    $t0, -11
  li    $t1, 12
  mult  $t0, $t1
  mflo  $a0
  li    $v0, 1
  syscall
Output Output Output









multu (unsigned) mfhi mult
  .text
  li    $t0, -2147483648

   # smallest signed word is
   #   0x80000000 = -231
   # = -2,147,483,648

  li    $t1, 2
  multu $t0, $t1
  mflo  $a0
  li    $v0, 1
  syscall
  .text 
  li    $t0, -2147483648

   # smallest signed word is
   #   0x80000000 = -231
   # = -2,147,483,648

  li    $t1, 2
  multu $t0, $t1 
  mfhi  $a0
  li    $v0, 1
  syscall
  .text
  li   $t0, -2147483648

   # smallest signed word is
   #   0x80000000 = -231
   # = -2,147,483,648

  li   $t1, 2
  mult $t0, $t1
  mfhi $a0
  li   $v0, 1
  syscall
Output Output Output













      “Lost Time is never found again.”    
      ― Benjamin Franklin, Poor Richard’s Almanack