Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1.(13 points) a.(4 points) Find the shortest sequence of MIPS machine instructions that will exchange (swap) the contents of registers St5 and St6 without use
1.(13 points) a.(4 points) Find the shortest sequence of MIPS machine instructions that will exchange (swap) the contents of registers St5 and St6 without use of any other register (and not creating overflow). swap St5 $t6 before $t5 = value St6 value2 after $t5 value2 St6-v aluel Show the shortest sequence of MIPS machine (not pseudo!) instructions for these C statements: b.(6 points) x7-x51+ Assume c corresponds to register St4 and the integer array x begins at memory location 1,048,600 (Hint: How many bits do we need to encode this address value?) c.(4 points) if (i j goto L Assume that variable i corresponds to register St2 and variable j corresponds to register St4 2. (7 points) The following program tries to copy words from the address in register Ss4 to the address in register Ss5, counting the number of words copied in register Ss2. The program stops copying when it finds a word equal to 0. You do not have to preserve the contents of registers St3. Ss4, and $s5This terminating word should be copied but not counted lw addi SW addi addi St3, 0(Ss4) Ss2, Ss2, 1 St3, 0(Ss5) Ss4, Ss4, 1 Ss 5. Ss5, 1 St3, $zero, Loop # Read next word from source # Increment count of words copied # Write to destination # Advance pointer to next source # Advance pointer to next destination # goto Loop if word copied ! bne zero There multiple bugs in this MIPS program. program. Fix them and turn in a bug-free version of this 3. (15 points) This C segment while (A[i] k) uses both a conditional branch and an unconditional jump each time through the loop (see below). Variables i, j, and k correspond to registers Ss3, $s4, and Ss5, and the base (start address) of the integer array A in Ss6. The result of the program is the final value of the index i in Ss3 Code before optimization Loop: add St, Ss3, Ss3 # Temporary register $t-i*2 addSt, St, Stl add St, Ss6 Iw beq Sto, Ss5, Exit addSs3, Ss3, Ss4 # Temporary register $tl-74 # Temporary register $t-address of A[i] # Temporary register $t0-Ali] # goto Exit if A[i]-k St0, 0(Stl) Loop # goto Loop Exit: (13 points) time through the loop i.e., no more than one jump/branch executed per iteration) a. Rewrite the assembly code so that it executes at most one branch or jump each b. (2 points) If the number of times when (Ali!-k) is true is 10, what is the number of instructions executed before and after optimization
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