The code for a function that is similar tofunction vfunct (a). We used vfunct toillustrate the use of a frame pointer in managing variable-sizestack frames. The new function aframe allocates space forlocal(a) C code1 #include <alloca.h>23 long aframe(long n, long idx, long *q) {4 long i;5 long **p = alloca(n * sizeof(long *));6 p[0] = &i;7 for (i = 1; i < n; i++)8 p[i] = q;9 return *p[idx];10 }(b) Portions of generated assembly codelong aframe(long n, long idx, long *q)n in %rdi, idx in %rsi, q in %rdx1 aframe:2 pushq %rbp3 movq %rsp, %rbp4 subq $16, %rsp Allocate space for i (%rsp = s )5 leaq 30(,%rdi,8), %rax6 andq $-16, %rax7 subq %rax, %rsp Allocate space for array p(%rsp = s )8 leaq 15(%rsp), %r89 andq $-16, %r8 Set %r8 to &p[0]⋮array p by calling library function alloca . This function issimilar to the more commonly used function malloc, except thatit allocates space on the run-time stack. The space isautomatically deallocated when the executing procedurereturns.(b) shows the part of the assembly code thatsets up the frame pointer and allocates space for localvariables i and p . It is very similar to the corresponding codefor vframe . Let us use the same notation as in Problem3.49 : The stack pointer is set to values s at line 4 and s atline 7. The start address of array p is set to value p at line 9.Extra space e may arise between s2 and p, and extra space emay arise between the end of array p and s1 .A. Explain, in mathematical terms, the logic in thecomputation of s2 .B. Explain, in mathematical terms, the logic in thecomputation of p.C. Find values of n and s1 that lead to minimum andmaximum values of e1 .D. What alignment properties does this code guarantee forthe values of s2 and p?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The code for a function that is similar to
function vfunct (a). We used vfunct to
illustrate the use of a frame pointer in managing variable-size
stack frames. The new function aframe allocates space for
local
(a) C code
1 #include <alloca.h>
2
3 long aframe(long n, long idx, long *q) {
4 long i;
5 long **p = alloca(n * sizeof(long *));
6 p[0] = &i;
7 for (i = 1; i < n; i++)
8 p[i] = q;
9 return *p[idx];
10 }
(b) Portions of generated assembly code
long aframe(long n, long idx, long *q)
n in %rdi, idx in %rsi, q in %rdx
1 aframe:
2 pushq %rbp
3 movq %rsp, %rbp
4 subq $16, %rsp Allocate space for i (%rsp = s )
5 leaq 30(,%rdi,8), %rax
6 andq $-16, %rax
7 subq %rax, %rsp Allocate space for array p
(%rsp = s )
8 leaq 15(%rsp), %r8
9 andq $-16, %r8 Set %r8 to &p[0]


array p by calling library function alloca . This function is
similar to the more commonly used function malloc, except that
it allocates space on the run-time stack. The space is
automatically deallocated when the executing procedure
returns.
(b) shows the part of the assembly code that
sets up the frame pointer and allocates space for local
variables i and p . It is very similar to the corresponding code
for vframe . Let us use the same notation as in Problem
3.49 : The stack pointer is set to values s at line 4 and s at
line 7. The start address of array p is set to value p at line 9.
Extra space e may arise between s2 and p, and extra space e
may arise between the end of array p and s1 .
A. Explain, in mathematical terms, the logic in the
computation of s2 .
B. Explain, in mathematical terms, the logic in the
computation of p.
C. Find values of n and s1 that lead to minimum and
maximum values of e1 .
D. What alignment properties does this code guarantee for
the values of s2 and p?

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education