Question: 2 2 . 9 LAB: Nested procedures Given the following C program and the mapping of registers to variables, complete the ARM implementation of procedure

22.9 LAB: Nested procedures
Given the following C program and the mapping of registers to variables, complete the ARM implementation of procedure Sum.
int Dif(int a, int b){
return b - a;
}
int Sum(int m, int n){
int p = Dif(n+1, m-1);
int q = Dif(m+1, n-1);
return p + q;
}
int main(){
int x, y;
z = x + y + Sum(x, y);
return 0;
}
Registers Variables
X19 x
X20 y
X21 z
Hint: Use X0, X1 as arguments and X2 as return value, according to the convention for procedure calling.
Ex: If the values of X19 and X20 are initialized in the simulator as:
Registers Data
X195
X2010
the result is stored in $s2:
Registers Data
X195
X2010
X2111
Note: Use the '+' button under the Registers display to initialize register values for X19 and X20.
ADDI X28, XZR, #1000// Assume Stack memory starts at 1000. Do not modify.
// Procedure Main (Do not modify)
Main:
ADD X0, XZR, X19
ADD X1, XZR, X20
BL Sum
ADD X21, X20, X19
ADD X21, X21, X2
B End
// Procedure Sum
Sum:
// Type your code here.
// Procedure Dif (Do not modify)
Dif:
SUB X2, X1, X0
BR X30
End:
 22.9 LAB: Nested procedures Given the following C program and the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!