Question: What are the contents of the 5-element array pointed by v right after jal sort returns to the main code? The remaining three problems in

What are the contents of the 5-element array pointed by v right after “jal sort” returns to the main code?


The remaining three problems in this exercise refer to a program that allocates memory for an array, ills the array with some numbers, calls the sort function from Figure 2.27, and then prints out the array. The main function of the program is as follows (given as both C and MIPS code):main() { Main Code in C int *v: int n=5; v=my_alloc(5); my_init(v.n); sort (v.n); main: 11 $50,5 move jal

The my_alloc function is defined as follows (given as both C and MIPS code). Note that the programmer of this function has fallen prey to the pitfall of using a pointer to an automatic variable arr outside the function in which it is defined.my_alloc in C n) { int *my_alloc(int int arr[n]: return arr: } my_alloc: addu SW move s11 sub move move 1wThe my init function is defined as follows (MIPS code): a. my_init: move move L: addi SW addiu addiu bne jr

Figure 2.27Move parameters Outer loop Inner loop Pass parameters and call Inner loop Outer loop sort: forltst: for2tst:exitl: lw Tw 1w 1w Tw addi jr Restoring registers $ra $50, 0($sp) $s1. 4($sp) # restore $s1 from stack $s2,

main() { Main Code in C int *v: int n=5; v=my_alloc(5); my_init(v.n); sort (v.n); main: 11 $50,5 move jal move move move MIPS Version of the Main Code move jal $a0,$s0 my_alloc. $s1, $v0 $a0,$sl $al, $50 jal my_init move $a0,$sl $al, $50 sort

Step by Step Solution

3.41 Rating (145 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To determine the contents of the 5element array pointed by v right after the function sort returns to the main code we need to follow the sequence of ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Organization Design Questions!