Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 5 (5 points) Find the shortest sequence of MIPS instructions that extrac

ID: 3880900 • Letter: P

Question

Problem 5 (5 points) Find the shortest sequence of MIPS instructions that extract bits 20 down to 16 from register Ss0 and uses the value of this field to replace bits 31 down to 27 in register Ssl without changing the other 27 bits of register Ss1. You will receive full credit as long as your code works correctly; you will receive one extra credit point if you use no more than five instructions. (Hint: You can use "srl Ss0, Ss0, 16" and "sll Ss0, Ss0, 27" to extract bits 20 down 16 from register St0 and place them in bits 31 down to 27 in register St0. Additionally, you may use another register (for example St0) and "or" instruction.).

Explanation / Answer

Code:

#the below 2 instructions extracts bits 16-20 and place them in 27-31
srl $s0, $s0, 16 #right shift $s0 by 16
sll $s0, $s0, 27 #left shift $s0 by 27

li $t0, 0x07FFFFFF #load $t0 to 0x07FFFFFF
and $s1, $s1, $t0 # and with $s1 to remove bits 27-31 of $s1
or $s1, $s1, $s0 #or with $s0 to put 27-31 bits of $s0 into 27-31 bits of $s1

Hope this helps. Do Upvote! :)