MIPS Multiplication: Using MUL, MULT and SLL

MIPS multiplication is a little bit tricky as compared to addition and subtraction, but here we will simplify it for you. To learn MIPS multiplication, you must go through the following topics:

MIPS multiplication uses arithmetic and logical format, and it can be performed using two opcode MUL and MULT. Both opcodes have a little bit difference in operation and syntax. We will discuss in detail below:

MIPS Multiplication Using MUL

The following example program describing the functionality of “mul” opcode. The mul instruction needed three operands registers.

MUL can be used in three possible ways:

  • MULTIPLY REGISTERS(mul $t1,$t2,$t3)

The above statement is also known as multiplications with overflow. Note the Hi register will be used to store high-order 32 bits, Lo and $t1 to low order 32 bits of the product of $t2 and $t3(we can use mfhi to access HI, mflo to access Lo)

  • MULTIPLY 16-bit SIGNED IMMEDIATE(mul $t1,$t2,-200)

Note Hi register to store high-order 32 bits, Lo and $t1 to low order 32 bits of the product of $t2 and any 16 bit signed immediate(we can use mfhi to access HI, mflo to access Lo)

  • MULTIPLY 32-bit SIGNED IMMEDIATE(mul $t1,$t2,100021)

Note Hi register to store high-order 32 bits, Lo and $t1 to low order 32 bits of the product of $t2 and any 32 bit signed immediate(we can use mfhi to access HI, mflo to access Lo)

Example Multiplication Program Using MUL

PROGRAM

OUTPUT

EXPLANATION:

In the above program, we initialized registers $s0 and $s1 with values 10 and 4. Then we performed multiplication using mul opcode. And at last, we printed the result of the multiplication.

MIPS Multiplication Using MULT

The following example program describing the functionality of “mult” opcode. The mult instruction needed two operands registers.

Example Multiplication Program Using MULT

PROGRAM

OUTPUT

EXPLANATION:

In the above program, we take two values from the user and then we performed multiplication using mult instruction. If we are multiplying two 32-bit number then the result become 64-bit so we need the first 32-bit result that is in lo(first 32 bit). In order to move the result to a register, we used instruction mflo.

MIPS Multiplication Using SLL

Sll also called shift left logical. It is the most efficient way to multiply the number in power of 2.

Example Multiplication Program Using SLL

PROGRAM

OUTPUT

EXPLANATION:

We use shift logical left instruction for multiplication. we have stored the value 2 in the register $t0. In line#6 we performed the logical operation. we have given the value 1, so it will be shifted one time.


State your Queries in the comment box!

Nauman Rehmat
 

Nauman Rehmat is the owner of Assembly Language Tuts.He is interested in Programming and SEO. He is also pursuing a degree in Computer Software Engineering from Comsats.