Docsity

CS 403 Assignment 2: C++ Code Translation & Stack Frame Analysis, Assignments of Programming Languages

Toggle sidebar
bg1
CS 403 – Assignment #2
DUE: September 18, 2001, In-Class
Electronic Submissions Not Accepted
Assignment should be completed on an individual basis
1. For the following C++-like program, write a translation into the pseudo-assembly
language presented in class (as amended).
2. Draw pictures of the run-time stack at each of following points. Label everything
precisely with addresses, etc, and include FP and SP:
a. Immediately after ugh is called from bar, and before ugh’s first
statement executes.
b. Immediately after blah is called the first time from ugh, and before
blah’s first statement executes.
c. Immediately after blah is called from bar, and before blah’s first
statement executes.
void blah(int x, int y, int z){
int a, b;
a=0;
a=x;
b=a;
}
void ugh(int a, int b){
blah(3, 4, 5);
blah(5, 4, 3);
}
void bar(int c, int d){
ugh(4, 5);
blah(3, 4, 5);
}
void main(void){
int x, y, z;
x=0;
bar(2, 3);
}
pf3
pf4
pf5

Partial preview of the text

Download CS 403 Assignment 2: C++ Code Translation & Stack Frame Analysis and more Assignments Programming Languages in PDF only on Docsity!

CS 403 – Assignment

DUE: September 18, 2001, In-Class

Electronic Submissions Not Accepted

Assignment should be completed on an individual basis

1. For the following C++-like program, write a translation into the pseudo-assembly

language presented in class (as amended).

2. Draw pictures of the run-time stack at each of following points. Label everything

precisely with addresses, etc, and include FP and SP:

a. Immediately after ugh is called from bar, and before ugh’s first

statement executes.

b. Immediately after blah is called the first time from ugh, and before

blah’s first statement executes.

c. Immediately after blah is called from bar, and before blah’s first

statement executes.

void blah(int x, int y, int z){

int a, b;

a = 0;

a = x;

b = a;

void ugh(int a, int b){

blah(3, 4, 5);

blah(5, 4, 3);

void bar(int c, int d){

ugh(4, 5);

blah(3, 4, 5);

void main(void){

int x, y, z;

x = 0;

bar(2, 3);

Code for blah: S SP+6, 0 S SP+6, SP+ S SP+7, SP+ J FP+

Code for ugh: S SP, FP SR FP, SP SR SP, SP+ S FP+3, 3 S FP+4, 4 S FP+5, 5 S FP+1, HERE+ J Code location for blah SR SP, FP SR FP, *FP S SP, FP SR FP, SP SR SP, SP+ S FP+3, 5 S FP+4, 4 S FP+5, 3 S FP+1, HERE+ J Code location for blah SR SP, FP SR FP, *FP J FP+

Code for bar: S SP, FP SR FP, SP SR SP, SP+ S FP+3, 4 S FP+4, 5 S FP+1, HERE+ J Code location for ugh SR SP, FP SR FP, *FP S SP, FP SR FP, SP SR SP, SP+ S FP+3, 3 S FP+4, 4 S FP+5, 5 S FP+1, HERE+ J Code location for blah SR SP, FP SR FP, *FP J FP+

Code for main: S FP+3, 0 S SP, FP SR FP, SP SR SP, SP+ S FP+3, 2 S FP+4, 3 S FP+1, HERE+ J Code location for bar SR SP, FP SR FP, *FP J FP+