29

I'm reading about division in MIPS and I've found that div

Divides $s by $t and stores the quotient in $LO and the remainder in $HI

https://web.archive.org/web/20201111203150/http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html

And Wikipedia says

HI and LO are used to access the multiplier/divider results, accessed by the mfhi (move from high) and mflo commands.

http://en.wikipedia.org/wiki/MIPS_architecture

Are HI and LO registers? What number registers are they?

4
  • And if they are not registers, are they spots in memory?
    – hodgesmr
    Feb 23, 2010 at 17:23
  • 1
    No, they are registers, it is just that they can't be encoded in the 5 bit register fields in MIPS instructions. Those "numbered" registers are accessed by using the appropriate number on the register field. The HI/LO registers have special instructions that allow them to be transfered to a "numbered" register. Feb 23, 2010 at 17:41
  • 1
    Related: Difference between rem and mfhi in MIPS. They exist to avoid write-back conflicts with normal 1-cycle latency instructions, and to simplify hazard detection for the general-purpose integer registers. Nov 14, 2018 at 19:00
  • 1
    note that they were removed in MIPS release 6
    – phuclv
    Oct 17, 2019 at 9:59

3 Answers 3

32

These are special registers used to store the result of multiplication and division. They are separate from the $0 .. $31 general purpose registers, not directly addressable. Their contents are accessed with special instructions mfhi and mflo (Move From HI/LO).

They are present in the Multiply Unit and are 32-bits each. More info here. As a pair, they hold the 64-bit full result of a 32x32-bit integer mult.


Raymond Chen's blog article The MIPS R4000, part 3: Multiplication, division, and the temperamental HI and LO registers has some very good info about early MIPS's non-intuitive behaviours, including mtlo / mtlo invalidating the previous hi / lo (respectively).

The incomplete integer instruction-set reference (linked in the question) for early MIPS also has some details, http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html, or see MIPS's official PDF manuals, or PDFs of manuals for classic MIPS CPUs.

2
12

HI and LO are not numbered registers, IIRC. They are only used to store the results of operations that would not fit in a single register (e.g. multiplying two 32-bit integers could result in a 64 bit integer, so the overflow goes in HI).

edit: according to this class description, they are indeed special registers, so they are not numbered, and only accessible using special commands.

3
  • The link seems to be behind a paywall. Jun 4, 2013 at 13:36
  • The link is dead (403)
    – FDinoff
    Dec 13, 2014 at 19:50
  • 1
    The high half of a full-multiply shouldn't be considered "overflow". It's just the high half (and a full-multiply like 32b * 32b => 64b can't overflow). If the high-half is non-zero, a 32b * 32b => 32b multiply would have overflowed... Oct 17, 2017 at 8:12
2

What LO does is that for multiplication, it stores the least significant bits, and HI stores the rest of the bits, but mainly, we just focus on the LO part for multiplication. In division, we focus on both. LO in division is where the quotient should be stored at and HI is the remainder.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.