Question

In: Computer Science

Briefly explain why there are no immediate multiply or divide integer ALU instructions for MIPS.

Briefly explain why there are no immediate multiply or divide integer ALU instructions for MIPS.

Solutions

Expert Solution

In MIPS assembly language, there is a multiplication instruction for signed integers, mult, and for unsigned integers multu. Since multiplication takes two 32 bit numbers and returns a 64 bit number, special treatment must be given to the result. The 64 bit product is located in a “product” register. You access the contents of this register using two separate instructions.

mult $s0, $s1 # Multiply the numbers stored in these registers.

# This yields a 64 bit number, which is stored in two

# 32 bits parts: "hi" and "lo"

mfhi $t0 # loads the upper 32 bits from the product register

mflo $t1 # loads the lower 32 bits from the product register

You can only read from the product register. You cannot manipulate it directly. In MARS, the p product register is shown as two 32 bit registers, HI and LO. If the HI register has all 0’s, then the product that is computed can be represented by 32 bits (what’s in the LO register). Otherwise, we have a number that is bigger than the maximum int and it would need to be treated separately.

About division:- To understand division, we need to recall some terminology. If we divide onepositive integer by another, say 78/21, or more generally ”dividend/divisor” then we get a quotient and a remainder, i.e.

dividend = quotient ∗ divisor + remainder

e.g. 78 = 3 ∗ 21 + 15

In MIPS, the divide instruction also uses the HI and LO registers, as follows:

div $s0, $s1 # Hi contains the remainder, Lo contains quotient

mfhi $t0 # remainder moved into $t0

mflo $t1 # quotient moved into $t1

The mult, div, mfhi, mflo are all R format instructions.

In more brief regarding to MIPS programming language:-

MIPS solution is 2 kinds of arithmetic instructions to recognize 2 choices:

–add (add), add immediate (addi), and subtract (sub) cause exceptions on overflow

–add unsigned (addu), add immediate unsigned (addiu), and subtract unsigned (subu) do not cause exceptions on overflow

Unsigned integers commonly used for address arithmetic where overflow ignored . MIPS C compilers always produce addu, addiu, subu.

Since MIPS includes add multiple and division and since immediate can be positive or negative, its range is :

Divide or multiply immediate with a negative number is equivalent to multiply and divide immediate with positive number, so divided or multiplied immediate would be redundant.

NOTE:- This is a very detailed answer and that's why it is lengthy, you must read it thoroughly and if any query raises please let me know in the comment section.


Related Solutions

MIPS assembly language. Why do "la label" instructions always need to be translated into 2 lines...
MIPS assembly language. Why do "la label" instructions always need to be translated into 2 lines of pseudo code? What about "lw label" instructions? Explain the similarities and differences in how they are implemented in MARS.
Explain by providing an example, why MIPS is not an accurate measure for computing performance among...
Explain by providing an example, why MIPS is not an accurate measure for computing performance among computers?
Explain why, empirically, there is mean reversion in AE (abnormal earnings). If you divide the sample...
Explain why, empirically, there is mean reversion in AE (abnormal earnings). If you divide the sample into deciles according to scaled current levels of AE, which stocks show the greatest AE persistence?
Explain why, empirically, there is mean reversion in AE (abnormal earnings). If you divide the sample...
Explain why, empirically, there is mean reversion in AE (abnormal earnings). If you divide the sample into deciles according to scaled current levels of AE, which stocks show the greatest AE persistence?
Explain why segmentation efforts based on attempts to divide the mass market using a few demographic...
Explain why segmentation efforts based on attempts to divide the mass market using a few demographic dimensions may be very disappointing.
i. Briefly explain why Dalton’s law is a limiting law. ii. Briefly explain how the low...
i. Briefly explain why Dalton’s law is a limiting law. ii. Briefly explain how the low temperature can affect ideality of a gas.
Briefly explain the following statements(ie, are they true? Why and why not?) The stock of a...
Briefly explain the following statements(ie, are they true? Why and why not?) The stock of a company with a single zero-coupon bond issue is a call option on the assets, "The claim of the bondholders, which is subject to default, can be viewed as a default -free bond and a short put on the assets. The bondholders have implicitly written the stockholders a put on the assets.”
I. Instructions: Read the following question and briefly answer the following: 1. Explain, How does teamwork...
I. Instructions: Read the following question and briefly answer the following: 1. Explain, How does teamwork benefit the leader's role?
Briefly explain why defining the scope of an audit is important.
Briefly explain why defining the scope of an audit is important.
Briefly explain why externalities result in inefficient outcomes.
Briefly explain why externalities result in inefficient outcomes.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT