The program snippets below represent a hierarchy of subroutine calls. There are errors in the code related to the preservation and recovery of the caller environment. Explain how you would rewrite the code for the foo and bar subroutines to ensure the caller environment is preserved.
Added by -Scar S.
Step 1
Typically, this includes the return address, saved frame pointer (if used), and any registers that the caller expects to remain unchanged after the subroutine call. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 57 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
We use a 32-bit operating system: Its int types, memory addresses, and registers, such as ESP, EBP, and EIP, are represented by 32 bits. We compile a program that calls this function in this operating system: void foo(int **input, int par) { int tag = par; int *arr[10]; printf("%x", tag); if(tag > 1) { while (*input != 0x0000) { *arr = *input; arr++; input++; } } printf("%x", tag); } (1) Please plot the stack frame of foo function before it returns. (2) Suppose you design a buffer overflow attack that successfully launches a shell by exploiting the foo function, after this successful BOF attack, will the two "printf" commands yield the same output? Please justify.
Akash M.
Consider the following program: program main int x; proc A; int x; proc B; { x := 3; call C; x := x + 1; print x; } (end B) proc C; int x; { x := 1; call D; print x; call F; print x; } (end C) { x := 2; call B; x := x + 1; print x; } (end A) proc D; proc E; int x; { x := 5; call F; print x; } (end E) { x := x + 1; print x; call E; x := x + 1; print x; } (end D) proc F; { print x; x := x + 2; } (end F) { x := 1; call A; print x; } (end main)
Sri K.
PROBLEM 3 (10 points) Consider the following code in C syntax (use static scoping). #include<stdio.h> int bar(int i) { i = 10; return i + 4; } int foo(int e, int y) { int a; int i; a = e + y; e = e + 2; i = y; y = i - 1; return bar(e); } int main() { int a = 0; int e[3] = {0, 1, 2}; int x; x = foo(a, e[a]); printf("%d-%d-%d-%d-%d ", a, e[0], e[1], e[2], x); return 0; } 5 points: If parameters are passed by value, the output of this program is (Explain by showing the call arguments to each function). 5 points: If parameters are passed by reference, the output of this program is explained with box and circle.
Aarya B.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD