Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

2 What are your current strengths in being an appreciative coach?

Answered: 1 week ago