Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 12 15 pts Add control states to the following to implement an exchange-with-memory instruction, xchg. such that xchg $rt immed($rs) acts rather like the
Question 12 15 pts Add control states to the following to implement an exchange-with-memory instruction, xchg. such that xchg $rt immed($rs) acts rather like the combination of a MIPS lw and sw: the result should be as if a sequence like t=memory[immed+rs); memory[immed+rs]=rt; rt=t; where t is a temporary register. In case you were wondering why one would ever want to do this, it's actually a very common operation for synchronizing between concurrently executing processes using sempahore... but MIPS doesn't happen to do it this way, so it's also not a MIPS instruction. You're probably wondering where the t register is. Well, pick one you're not using... perhaps y (although you have to be careful about when you compute immed+rs for that to work). You should use the encoding suggested by the when below, so an instruction like xchg $9,4($10) would be encoded as op(3)+rt(9)+rs(10)+immed(4). when (op) (op(3)) Xchg Start: PCout, MARin, MEMread, Yin CONST(4), ALUadd, Zin, UNTILmfc MDRout, I Rin Zout, PCin, JUMPonop HALT/* Should end here on undecoded op */ Xchg: Edit View Insert Format Tools Table 12pt Paragraph B I U Tv Dav 12 FI va Dz O words > Question 12 15 pts Add control states to the following to implement an exchange-with-memory instruction, xchg. such that xchg $rt immed($rs) acts rather like the combination of a MIPS lw and sw: the result should be as if a sequence like t=memory[immed+rs); memory[immed+rs]=rt; rt=t; where t is a temporary register. In case you were wondering why one would ever want to do this, it's actually a very common operation for synchronizing between concurrently executing processes using sempahore... but MIPS doesn't happen to do it this way, so it's also not a MIPS instruction. You're probably wondering where the t register is. Well, pick one you're not using... perhaps y (although you have to be careful about when you compute immed+rs for that to work). You should use the encoding suggested by the when below, so an instruction like xchg $9,4($10) would be encoded as op(3)+rt(9)+rs(10)+immed(4). when (op) (op(3)) Xchg Start: PCout, MARin, MEMread, Yin CONST(4), ALUadd, Zin, UNTILmfc MDRout, I Rin Zout, PCin, JUMPonop HALT/* Should end here on undecoded op */ Xchg: Edit View Insert Format Tools Table 12pt Paragraph B I U Tv Dav 12 FI va Dz O words >
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started