0
\$\begingroup\$

I am a bit confused about lh (load halfword) instruction. Would it be correct to say that it gets the contents of the address just like in load word instruction but then takes the 16 rightmost bits and sign extends them?

Load word

So considering the picture above for load word, the datapath would be the same up to Read Data in Data Memory, but then the 16 rightmost bits would be sign extended and passed as write data to the register file instead of the whole 32 bits at read data.

Could someone confirm I am understanding the instruction correctly? It is sort of difficult to say what is going on.

\$\endgroup\$
3
\$\begingroup\$

You are mostly right. When in doubt, read the source material (in this case, the instruction set reference).

Where you may not be right is that according to MIPS, only 16 bits are read from memory. This doesn't matter much if you're reading from RAM, but for memory-mapped I/O, some peripherals will change state when a "memory" location is read from or written -- for example, a FIFO read will read the top of the FIFO and then pop.

Where this makes a difference is if two such memory locations are packed next to each other in a peripheral's memory map, or where a FIFO is packed next to a general-purpose register (i.e. a stack register).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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