Problem 0. Below is the C code for 3 functions, foo, bar, and bazz; foo calls bar, which calls bazz. Each has some local variables. long bazz (long *p1, long q) { if (q < 3L) return *p1 + 1; else return bazz (p1,q−1)+1; } long bar (long *m, long *n) { long x = *n; *m += bazz (m, 3L); return x + *m; } long foo(long x, long *y) { long a = x + *y; return *y+bar (y, &a); } Here is the assembly code generated for each: bazz: .L2: cmpq $2, %rsi jg .L2 movq (%rdi), %rax addq $1, %rax ret subq $8, %rsp subq $1, %rsi call bazz addq $1, %rax addq $8, %rsp ret
Problem 0. Below is the C code for 3 functions, foo, bar, and bazz; foo calls bar, which calls bazz. Each has some local variables. long bazz (long *p1, long q) { if (q < 3L) return *p1 + 1; else return bazz (p1,q−1)+1; } long bar (long *m, long *n) { long x = *n; *m += bazz (m, 3L); return x + *m; } long foo(long x, long *y) { long a = x + *y; return *y+bar (y, &a); } Here is the assembly code generated for each: bazz: .L2: cmpq $2, %rsi jg .L2 movq (%rdi), %rax addq $1, %rax ret subq $8, %rsp subq $1, %rsi call bazz addq $1, %rax addq $8, %rsp ret
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question

Transcribed Image Text:Problem 0. Below is the C code for 3 functions, foo, bar, and bazz; foo calls bar, which calls
bazz. Each has some local variables.
long bazz (long *p1, long q) {
if (q < 3L)
return *p1 + 1;
else
return bazz (p1,q-1)+1;
}
long bar (long *m, long *n) {
long x = *n;
*m += bazz (m, 3L);
return x + *m;
}
long foo (long x, long *y) {
long a= x + *y;
return *y+ bar (y, &a);
}
Here is the assembly code generated for each:
bazz:
.L2:
cmpq $2, %rsi
jg .L2
movq (%rdi), %rax
addq $1, %rax
ret
subq $8, %rsp
subq $1, %rsi
call bazz
addq $1, %rax
addq $8, %rsp
ret

Transcribed Image Text:bar:
foo:
pushq %rbp
pushq %rbx
subq $8, %rsp
movq %rdi, rbx
movq (rsi), %rbp
movl $3, %esi
call bazz
addq (%rbx), rax
movq rax, (%rbx)
addq %rbp, %rax
addq $8, %rsp
popq rbx
popq %rbp
ret
pushq rbx
subq $16, %rsp
movq %rdi, %rax
movq %rsi, %rdi
xorl %edx, %edx
movq (%rsi), %rbx
addq rbx, rax
movq %rax, (%/rsp)
movq %rsp, %rsi
call bar
addq rbx, rax
jne .L12
addq $16, %rsp
popq rbx
ret
Suppose foo (10,&y) is called from main, where long y contains the value 0. Assume register %rbx
contains a value a, %rbp contains 3., and %rsp contains y at the time foo is invoked.
a. Draw a diagram of the stack immediately after the second invocation of bazz Treat the stack
as an array of 8-byte quantities. The stack frame of main will be at the top of the diagram.
(You will only know the contents of y in the frame of main) The top of the stack (i.e., the
frame of the recursive invocation of bazz) at the bottom. Show the contents of each long on
the stack. If it is unknown, leave it blank.
b. What value does foo (10,&y) return?
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 7 steps with 1 images

Similar questions
Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY