1. Write complete code for the following switch statement in MIPS. Print the val
ID: 3588212 • Letter: 1
Question
1. Write complete code for the following switch statement in MIPS. Print the value the final value of “x”. “x” should be provided as user input.
switch(x) {
case 0: x + 1; break;
case 1: x + 3; break;
case 2: x + 5; break;
}
2.Write complete code for the following switch statement in MIPS. Print the final value of “y”. “x” should be provided as user input. “a” and “b” should have the values 12 and 5 respectively.
switch(x) {
case 0: y = a + b; break;
case 1: y = a – b; break;
case 2: y = a + x; break;
}
Explanation / Answer
The MIPS code to implement block copy without the bcp instruction is as follows:
loop:
lw $t4, 0($t1)
sw $t4, 0($t2)
addi $t1, $t1, 4
addi $t2, $t2, 4
subi $t3, $t3, 1
bne $t3, $zero, loop
To implement block copy with this instruction: li $t1, src li $t2, dst li $t3, count bcp Assuming each instruction in the MIPS code of ‘loop’ takes 1 cycle, for doing a 100-word copy the total number of cycles taken is 6*100 = 600 cycles.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.