Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C2A2E3 (6 points - Drawing only - No program required) Please refer to figure 8 of note 12.4D and figure 5 of note12.6C in the

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
C2A2E3 (6 points - Drawing only - No program required) Please refer to figure 8 of note 12.4D and figure 5 of note12.6C in the course book. Both illustrate the final state of the call stack before any returns have occurred in their respective programs. Create a similar single figure based upon the assumptions and program code provided below. If you create multiple figures you are doing this exercise incorrectly. Your figure must: . Begin with the "startup" stack frame shown in figure A on the next page and append additional stack frames using the general format and item ordering illustrated in the next frame in that figure. Show only stack frame items for the functions below. . Use a double question mark for all return object values, values dependent upon return objects, and values for which you believe insufficient information has been provided. Represent all addresses and BP offsets in hexadecimal and all other numeric values in decimal. Suffix all hexadecimal values with anh but do not suffix decimal values. Create your figure using a computer application of your choice, such as a text editor, Word, Visio, Excel, etc. Then convert it to a PDF file named C2A2E3_StackFrames.pdf for submission. NO CREDIT will be given if your file: . ...contains anything hand-drawn or difficult to read, or ...cannot be printed on one standard 8-1/2" by 11" page without size reduction, or ...contains a stack frame item that will not fit entirely on one line. The code below uses different types and sizes for exercise diversity. Assume the following: Any necessary header files and prototypes are present. . "Pascal calling convention" short: 3 bytes, int: 4 bytes, long: 8 bytes, addresses(pointers): 6 bytes int main() The "startup function" calls main { and main returns to it. Function main int result = gcd(176, 77); Operation Instruction Address return 0; } assignment to result 580h long gcd(int x short y) { Function gcd if (y ==0) return x Operation Instruction Address return godly.x%y); the return on line 36 1E0h } Waypoints: Check the following to help you determine if you might have a problem: The gcd function will have 4 stack frames, each containing 5 items. The absolute address of the last item in the last stack frame will be 839h. . There should be exactly 7 stack values that are double questions marks. Continued on the next page... Submitting your solution Send your PDF file to the assignment checker with the subject line C2A2E3_ID. where ID is your 9-character UCSD student ID. See the course document titled "How to Prepare and Submit Assignments for additional exercise formatting, submission, and assignment checker requirements. Figure A Required "startup" Stack Frame and General Stack Frame Format The figure below was created as a table in Microsoft Word, but you may use any computer application you wish as long as you present the required information in the same basic format. Place a divider prior to each stack frame that indicates the name of the function. If the function is being used recursively. indicate the recursion level after the name starting with 1. Relative Absolute Stack Description Address Address Value startup BP+6h BBFh 1014h Function Return Address BP BB9h eh Previous Frame Address Function Name 1 BP+... Return Object BP+... names of specifically ordered formal parameters, BP+... BP+... As many of these stack frames as needed. BP+... BP BP-.. Function Return Address Previous Frame Address BP-... BP-... names of arbitrarily ordered Local automatic variables! Notes: 1. Space for the return object, formal parameters, and Local automatic variables is not allocated if the function does not have them. 2. The order of formal parameters depends upon which calling convention is used. 3. Only indicate a Level if the function is being used recursively. Figure 8 Stack Values ?? Description ?? Stack View fcnB complete Memory Addresses Relative Absolute BP+?? ?? BP+?? FC2h BP+8h FCO BP+4h FBCh startup Stack Frame: ?? ?? ?? main Stack Frame BP FB8h ?? With Relative Addresses Shown ?? Return Object (int) Function Return Address Previous Frame Address horse pig Function Return Address Previous Frame Address 2.8 BP+10h FB0h BP+8h FA8h 7.5 BP+4h FA4h 3AC2h FB8h fcnA Stack Frame BP FAOh F9Eh XA BP-2h BP-4h ?? 81 F9Ch F9Ah YA dog BP+Ah 29 BP+8h -7 cat F98h F94h BP+4h 21F8h fcnB Stack Frame BP F90h BP F90h Function Return Address Previous Frame Address WB FAOh 5.6 BP-8h F88h BP-10h F80h SP F80h ?? zB Figure 5 Stack View Stack Values 22 ?? ?? ?? startup Stack Frame Memory Addresses Relative Absolute BP+?? ?? BP+?? FA9h BP+6h FA7h BP+3h FA4h BP FA1h BP-2 F9Fh BP+3 F9Ch BP F99h BP+6h F97h Description ?? ?? Retum Object (int) Function Return Address Previous Frame Address Final State main Stack Frame ?? ?? 200h FA1h Function Return Address Previous Frame Address BP+3h 397 116h F99h F94h F91h F8Fh value Function Return Address Previous Frame Address Stack BP BP+6h 39 value Stack Recur Ready Frame 3 : Frame 2 : Frame 1 Frame Recur Stack Recur Stack 7BEh BP+3h BP BP+6h F8Ch F89h F91h 3 Function Return Address Previous Frame Address value Function Return Address Previous Frame Address F87h F84h F81h 7BE BP+3h BP BP F81h SP F81h F89h C2A2E3 (6 points - Drawing only - No program required) Please refer to figure 8 of note 12.4D and figure 5 of note12.6C in the course book. Both illustrate the final state of the call stack before any returns have occurred in their respective programs. Create a similar single figure based upon the assumptions and program code provided below. If you create multiple figures you are doing this exercise incorrectly. Your figure must: . Begin with the "startup" stack frame shown in figure A on the next page and append additional stack frames using the general format and item ordering illustrated in the next frame in that figure. Show only stack frame items for the functions below. . Use a double question mark for all return object values, values dependent upon return objects, and values for which you believe insufficient information has been provided. Represent all addresses and BP offsets in hexadecimal and all other numeric values in decimal. Suffix all hexadecimal values with anh but do not suffix decimal values. Create your figure using a computer application of your choice, such as a text editor, Word, Visio, Excel, etc. Then convert it to a PDF file named C2A2E3_StackFrames.pdf for submission. NO CREDIT will be given if your file: . ...contains anything hand-drawn or difficult to read, or ...cannot be printed on one standard 8-1/2" by 11" page without size reduction, or ...contains a stack frame item that will not fit entirely on one line. The code below uses different types and sizes for exercise diversity. Assume the following: Any necessary header files and prototypes are present. . "Pascal calling convention" short: 3 bytes, int: 4 bytes, long: 8 bytes, addresses(pointers): 6 bytes int main() The "startup function" calls main { and main returns to it. Function main int result = gcd(176, 77); Operation Instruction Address return 0; } assignment to result 580h long gcd(int x short y) { Function gcd if (y ==0) return x Operation Instruction Address return godly.x%y); the return on line 36 1E0h } Waypoints: Check the following to help you determine if you might have a problem: The gcd function will have 4 stack frames, each containing 5 items. The absolute address of the last item in the last stack frame will be 839h. . There should be exactly 7 stack values that are double questions marks. Continued on the next page... Submitting your solution Send your PDF file to the assignment checker with the subject line C2A2E3_ID. where ID is your 9-character UCSD student ID. See the course document titled "How to Prepare and Submit Assignments for additional exercise formatting, submission, and assignment checker requirements. Figure A Required "startup" Stack Frame and General Stack Frame Format The figure below was created as a table in Microsoft Word, but you may use any computer application you wish as long as you present the required information in the same basic format. Place a divider prior to each stack frame that indicates the name of the function. If the function is being used recursively. indicate the recursion level after the name starting with 1. Relative Absolute Stack Description Address Address Value startup BP+6h BBFh 1014h Function Return Address BP BB9h eh Previous Frame Address Function Name 1 BP+... Return Object BP+... names of specifically ordered formal parameters, BP+... BP+... As many of these stack frames as needed. BP+... BP BP-.. Function Return Address Previous Frame Address BP-... BP-... names of arbitrarily ordered Local automatic variables! Notes: 1. Space for the return object, formal parameters, and Local automatic variables is not allocated if the function does not have them. 2. The order of formal parameters depends upon which calling convention is used. 3. Only indicate a Level if the function is being used recursively. Figure 8 Stack Values ?? Description ?? Stack View fcnB complete Memory Addresses Relative Absolute BP+?? ?? BP+?? FC2h BP+8h FCO BP+4h FBCh startup Stack Frame: ?? ?? ?? main Stack Frame BP FB8h ?? With Relative Addresses Shown ?? Return Object (int) Function Return Address Previous Frame Address horse pig Function Return Address Previous Frame Address 2.8 BP+10h FB0h BP+8h FA8h 7.5 BP+4h FA4h 3AC2h FB8h fcnA Stack Frame BP FAOh F9Eh XA BP-2h BP-4h ?? 81 F9Ch F9Ah YA dog BP+Ah 29 BP+8h -7 cat F98h F94h BP+4h 21F8h fcnB Stack Frame BP F90h BP F90h Function Return Address Previous Frame Address WB FAOh 5.6 BP-8h F88h BP-10h F80h SP F80h ?? zB Figure 5 Stack View Stack Values 22 ?? ?? ?? startup Stack Frame Memory Addresses Relative Absolute BP+?? ?? BP+?? FA9h BP+6h FA7h BP+3h FA4h BP FA1h BP-2 F9Fh BP+3 F9Ch BP F99h BP+6h F97h Description ?? ?? Retum Object (int) Function Return Address Previous Frame Address Final State main Stack Frame ?? ?? 200h FA1h Function Return Address Previous Frame Address BP+3h 397 116h F99h F94h F91h F8Fh value Function Return Address Previous Frame Address Stack BP BP+6h 39 value Stack Recur Ready Frame 3 : Frame 2 : Frame 1 Frame Recur Stack Recur Stack 7BEh BP+3h BP BP+6h F8Ch F89h F91h 3 Function Return Address Previous Frame Address value Function Return Address Previous Frame Address F87h F84h F81h 7BE BP+3h BP BP F81h SP F81h F89h

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

More Books

Students also viewed these Databases questions