Question: Exercise 2.32 The fi rst three problems in this exercise assume that function swap, instead of the code in Figure 2.24, is defi ned in
Exercise 2.32 The fi rst three problems in this exercise assume that function swap, instead of the code in Figure 2.24, is defi ned in C as follows:
a. void swap(int v[], int k, int j){
int temp;
temp=v[k];
v[k]=v[j];
v[j]=temp;
}
b. void swap(int *p){
int temp;
temp=*p;
*p=*(p+1);
*(p+1)=*p;
}
2.32.1 [10] <2.13> Translate this function into MIPS assembler code.
2.32.2 [5] <2.13> What needs to change in the sort function?
2.32.3 [5] <2.13> If we were sorting 8-bit bytes, not 32-bit words, how would your MIPS code for swap in 2.32.1 change?
For the remaining three problems in this exercise, we assume that the sort function from Figure 2.27 is changed in the following way:
a. Use s-registers instead of t-registers.
b. Use the bltz (branch on less than zero) instruction instead of slt and bne at the for2tst label.
2.32.4 [5] <2.13> Does this change affect the code for saving and restoring registers in Figure 2.27?
2.32.5 [10] <2.13> When sorting a 10-element array that was already sorted, how many more (or fewer) instructions are executed as a result of this change?
2.32.6 [10] <2.13> When sorting a 10-element array that was sorted in descending order (opposite of the order that sort() creates), how many more (or fewer)
instructions are executed as a result of this change?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
