Please find JPG file of the question as attached
Main Topics
Browse All TopicsSome computers have explicit instructions to extract an arbitrary field from a 32-
bit register and to place it in the least significant bits of a register.
Find the shortest sequence of MIPS instructions that extracts a field for the
constant values i=5 and j=22 from register $t3 and places it in register $t0. (Hint:
It can be done in two instructions)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Right. That clarifies it. A "field" is a series of bits between two given bit positions.
For this question, you have to get the bits starting at bit index 5, till bit index 22 (which is 22 - 5 = 17 bits total) from the $t3 register, and place them in the least significant bits (0 till 17) of the $t0 register.
Take a look at the instructions you have available, and see which ones you could use to do this ...
>> Ohh ok, so in that case i have to use "srl $t0, $t3, 6"
Indeed.
>> and to make sure that the other 15 higher bits of the $t0 register are assigned 0s , I will use
>> "LUI $t0, 0"
The lui instruction would set the high order 16 bits to the immediate value provided, and the low order 16 bits to 0. So effectively, it would set all bits of the register to 0 - that's not what you want.
Basically, this is a masking operation, and the usual way to do that is by using a bitwise AND.
>> so in that case for the bitwise AND procedure to the $t0 register before i do the "srl $t0, $t3, 6"
That will not have an impact.
The and instruction (and $t0, 0) will set the $t0 register to all zero's.
The shift instruction (srl $t0, $t3, 6) will then overwrite all those zero's with the shifted value from $t3.
So, if $t3 contained 01010101010101010101010101
00000001010101010101010101
while what was intended is :
00000000000000010101010101
If you don't like using the bitwise AND, there's another way you can do it. You can use a combination of shift left and shift right to keep only the required part (bits 6 through 23).
>> do i have to first
>> "sll $t0, $t3, 10"
>> and then
>> "srl $t3, $t3, 16"
That's the idea. Now you just have to get the values right ;) If you shift left by 10, then you discard the 10 leftmost bits, but that's too much, since you need to keep the bit at index 22 (remember that indexes go from 0 to 31). Similarly, the value 16 will need to be adapted.
And remember that the second instruction should work on $t0, not $t3.
Business Accounts
Answer for Membership
by: Infinity08Posted on 2009-09-18 at 01:54:26ID: 25363915
The terminology used is a bit non-standard.
How is "field" defined in your case ?
What is understood by "field for constant values" ?