Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MIPS, what are HI and LO

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?

like image 564
hodgesmr Avatar asked Feb 23 '10 17:02

hodgesmr


People also ask

What is Hi and Lo register?

The HI and LO registers are 32-bit registers which hold or accumulate the results of a multiplication or addition. You cannot operate on them directly. They are set by a suitable arithmetic operation, and by special instructions for moving values in and out.

What does SLL do in MIPS?

SLL -- Shift left logicalShifts a register value left by the shift amount listed in the instruction and places the result in a third register. Zeroes are shifted in.

What does Li and La mean in MIPS?

When you'd use li and when you'd use la depends on the context. If the value you're loading is going to be used as an address you would typically use la to load it, and otherwise you'd typically use li .

What does Li mean in MIPS?

Load Immediate (li) The li pseudo instruction loads an immediate value into a register.


2 Answers

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.

like image 136
codaddict Avatar answered Sep 23 '22 17:09

codaddict


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.

like image 39
Sean Avatar answered Sep 22 '22 17:09

Sean