Question

In: Computer Science

Right before your function f from Exercise 2.32 returns, what do we know about contents of registers X5, X29, X30, and SP?

2.32  Translate function f into LEGv8 assembly language. If you need to use registers X10 through X27, use the lower-numbered registers first. Assume the function declaration for g is “int g(int a, int b)”. The code for function f is as follows:


int f(int a, int b, int c, int d){
return g(g(a,b),c+d);
}

2.34 Right before your function f from Exercise 2.32 returns, what do we know about contents of registers X5, X29, X30, and SP? Keep in mind that we know what the entire function f looks like, but for function g we only know its declaration.

 

Solutions

Expert Solution

Transalation of above given code in LEGv8 (asm low level machine code(language))

For 64 bit system we can user register form X0 to X30

For 32 bit system we can user register form W0 to W30

int f(int a, int b, int c, int d) {  

return g(g(a,b),c+d);

}

int g(int a, int b, int c, int d) { // initializing as int type output data type

return a+b;

}

--------  LEGv8 ----- g function -- sample return type of g -- replacing with other scenario can change the ouput of function f

g:

SUBI SP,SP,#24 // Save X10, X9, X19 on stack

MOV X10, SP,#10 // Moving stack for a to register X10

MOV X11 SP,#20 // Moving stack for b to register X11

ADD X10, X11, X12 // X12 = X11 + X12

ret X12 // returning register value in X12

---------------------------------------------------------------

--------  LEGv8 ----- f function

f :

MOV X13, SP,#10 // Moving stack for a to register X10

MOV X15 SP,#20

LDR X13, X15, =g, X16 // X16 = g( X13, X14 ); calling g with argument

LDR X16, X17, =g, X18 // X18 = g( X16, X17 );

ret X18 // return X18 as output.

---- end ---


Related Solutions

1. what is genome sequencing? what do we now know about the human genome from sequencing...
1. what is genome sequencing? what do we now know about the human genome from sequencing it? 2. explain different applications of genomics. What are SNPs is and how are they useful? 3. what are the uses of biotechnology in medicine?
What do we know about the relationships that have low confidence? 6. What about the ones...
What do we know about the relationships that have low confidence? 6. What about the ones with high confidence?
What do we know about the biological and societal influences on sexual orientation?
What do we know about the biological and societal influences on sexual orientation?
Aristotle said, " People in government exercise a teaching function and we see what they do...
Aristotle said, " People in government exercise a teaching function and we see what they do and think and that's how we should act. Unfortunately, when they do things that are underhanded or dishonest, that teaches too". With 5 relevant examples, discuss whether the statement is true or false. this is all the question. please its urgent, thank you
This problem is about the definition of periodic function. We assume you already know intuitively what...
This problem is about the definition of periodic function. We assume you already know intuitively what periodic means, and now we want a formal definition. For simplicity, we will restrict ourselves to functions with domain R. A naive (but incorrect) definition of periodic function with period T is f (x + T ) = f (x) Without accompanying words, this is not a good definition because it does not introduce the variables x and T and it does not explain...
What is your personal-best leadership story and what do you already know firsthand about leadership from...
What is your personal-best leadership story and what do you already know firsthand about leadership from your experience?
What do we know, both culturally and morphologically, about the emergence and geographic spread of the...
What do we know, both culturally and morphologically, about the emergence and geographic spread of the genus Homo? Please answer this question in more than 100 word
Before you put your money down and purchase a stock, what should you know about it?...
Before you put your money down and purchase a stock, what should you know about it? Explain
What do we know about Homo floresiensis? How old is it, where did it live, what...
What do we know about Homo floresiensis? How old is it, where did it live, what did it look like? And, why is this a considered, by many, to be a controversial find? What is meant by race? If you had a friend who told you that there were three clearly defined races, and another friend insisted that there were really five races, would you agree or disagree with each of them and why? Why can’t everyone agree on the...
1)a)The COFD = 8.5% and ROFE is 8.8%. What do we know about ROFA? ROFA is...
1)a)The COFD = 8.5% and ROFE is 8.8%. What do we know about ROFA? ROFA is less than 8.5% ROFA is greater than 8.5% but less than 8.8% ROFA is greater than 8.8% There is insufficient information to determine a range for ROFA b)The COFD = 8.5% and ROFA is 8.8%. What do we know about ROFE? ROFE is less than 8.5% ROFE is greater than 8.5% but less than 8.8% ROFE is greater than 8.8% There is insufficient information...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT