subject

For this exercise, we will examine the code generated by GCC for functions that have structures as arguments and return values, and from this see how these language features are typically implemented. The following C code has a function process having structures as argument and return values, and a function eval that calls process. typedef struct {long a[2]; long *p;} strA; typedef struct {long u[2]; long q;} strB strB process(strA s) {strB r; r. u[0] = s. a[1]; r. u[1] = s. a[0]; r. q = *s. p; return r;} long eval (long x, long y, long z) {strA s; s. a[0] = x; s. a[1] = y; s. p = &z; strB r = process(s); return r. u[0] + r. u[1] + r. q;} Gcc generates the following code for these two functions: strB process(strA s) process: movq %rdi, %rax movq 24(%rsp), %rdx movq (%rdx), %rdx movq 16(%rsp), %rcx movq %rcx, (%rdi) movq 8(%rsp), %rcx movq %rcx, 8(%rdi) movq %rdx, 16(%rdi) ret long eval(long x, long y, long z) x in %rdi, y in %rsi, z in %rdx eval: subq $104, %rsp movq %rdx, 24(%rsp) leaq 24(%rsp), %rax movq %rdi, (%rsp) movq %rsi, 8(%rsp) movq %rax, 16(%rsp) leaq 64(%rsp), %rdi call process movq 72(%rsp), %rax addq 64(%rsp), %rax addq 80(%rsp), %rax addq $104, %rsp ret A. We can see on line 2 of function eval that it allocates 104 bytes on the stack. Diagram the stack frame for eval, showing the values that it stores on the stack prior to calling process.
B. What value does eval pass in its call to process?
C. How does the code for process access the elements of structure argument s?
D. How does the code for process set the fields of result structure r?
E. Complete your diagram of the stack frame for eval, showing how eval accesses the elements of structure r following the return from process.
F. What general principles can you discern about how structure values are passed as function arguments and how they are returned as function results?

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 07:30
Jasper and samantha are in a robotics competition. the guidelines state that the robots should be able to move a 10-gram weight at least 2 meters and turn in a circle. jasper and samantha have already built the robot. which step of the design process should they follow next to decide whether their robot meets the minimum criteria for the competition?
Answers: 1
question
Computers and Technology, 22.06.2019 20:40
Assume that there is a 4% rate of disk drive failure in a year. a. if all your computer data is stored on a hard disk drive with a copy stored on a second hard disk drive, what is the probability that during a year, you can avoid catastrophe with at least one working drive? b. if copies of all your computer data are stored on three independent hard disk drives, what is the probability that during a year, you can avoid catastrophe with at least one working drive?
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
Quic which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
question
Computers and Technology, 24.06.2019 03:40
4. does the kernel phenotype distribution support the idea that the cob is the result of a dihybrid cross? what information supports your answer? if a dihybrid cross (i.e. f1 to f2 of standard mendelian crosses) is not indicated what conditions might contribute to this finding.
Answers: 2
You know the right answer?
For this exercise, we will examine the code generated by GCC for functions that have structures as a...
Questions
question
Mathematics, 27.03.2020 20:49
question
Mathematics, 27.03.2020 20:49
question
Mathematics, 27.03.2020 20:49
question
Mathematics, 27.03.2020 20:49
question
Mathematics, 27.03.2020 20:49