Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In my question, there are the following C code and Assembly: C Code: typedef struct{ long a[2]; long *p; } strA; typedef struct{ long u[2];

In my question, there are the following C code and Assembly:

C Code: 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; 

Assembly:

strB process(strA s) 1 process: 2 movq %rdi, %rax 3 move 24(%rsp), %rdx 4 movq (%rdx), %rdx 5 movq 16(%rsp), %??? 6 movq %rcx, (%rdi) 7 movq 8(%rsp), %rcx 8 movq %rcx, 8(%rdi) 9 movq %rdx, 16(%rdi) 10 ret long eval(long x, long y, long z) x in %rdi, y in %rsi, z in %rdx 1 eval: 2 subq $104, %rsp 3 movq %rdx, 24(%rsp) 4 leaq 24(%rsp), %rax 5 movq %rdi, (%rsp) 6 movq %rsi, 8(%rsp) 7 movq %rax, 16(%rsp) 8 leaq 64(%rsp), %rdi 9 call process 10 movq 72(%rsp), %rax 11 addq 64(%rsp), %rax 12 addq 80(%rsp), %rax 13 addq $104, %rsp 14 ret 

The questions and a few trying answers are as follow, hope you could help me with the remaining questions. Thank you very much!

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.

Before eval calls process, it moves z into the 24th byte of the stack and moves the address into rax, then it moves x to the bottom of the stack at the 0th byte, and y on top of x, and z on top of y. So it would look like: xyzz . I don't know how to diagram the stack frame here.

B. What value does eval pass in its cal to process?

It loads in the address at the 64th byte into rdi to be used for the process.

C. How does the code for process access the elements of structure arguments?

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.

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

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions

Question

Why aren't heavier elements much larger than lighter elements?

Answered: 1 week ago