为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

Ch7--Exercises

2018-09-08 3页 doc 28KB 19阅读

用户头像

is_087967

暂无简介

举报
Ch7--ExercisesExercises-Ch7 1.We assume that the storage organization and the form of activation record used in C language program run-time stack storage allocation are as following. Please construct the run-time stack map when it gets the maximum size for the first time for th...
Ch7--Exercises
Exercises-Ch7 1.We assume that the storage organization and the form of activation record used in C language program run-time stack storage allocation are as following. Please construct the run-time stack map when it gets the maximum size for the first time for the following C program (10%). Storage Organization of C Language The Form of Activation Record of any a function in C The C program is as the following: #include int x,y; int main() { x=5; y=f(x); } int f(int n) { if (n<=1) return 1; else if ( n==2) return 2; else { int t1,t2,t3,t4,t; t1=f(n-1); t2=f(n-2); t3=f(n-3); t4=t1+t2 t=t3+t4; return t } } Notes: 1) Here we assume that the caller’s sp of Main function is the start address of global variable data area, and the returned address in the activation record of a function (including Main function) is filled by the operating system automatically, you might not care it. 2) The initial value of variable X is 5, the start address of stack used in the program is K. 3) The stack map may get its maximum size for several times, here we ask you draw the stack map at maximum size for the first time. 2. We assume that the storage organization and the form of activation record used in C language program run-time stack storage allocation are as above. Please construct the run-time stack map when it gets the maximum size for the following C program (10%). The C program is as the following: #include int x,y,z; int main() { x=40; y=35; z=f(x,y); } int f(int m, int n) { if (n>m) { int t; t=f(n,m); return t } else if (n==0) return m; else { int t1,t2; t1=m % n; //remainder of m/n t2=f(n,t1); return t2 } } Notes: 1) Here we assume that the caller’s sp of Main function is the start address of global variable data area, and the returned address in the activation record of a function (including Main function) is filled by the operating system automatically, you might not care it. 2) The initial value of variable X and Y are 40 and 35 respectively, the start address of stack used in the program is K. ….. Activation Record of the function called by Main function Activation Record of Main function Global Variable Data Area SP TOP Unit for Returned Value of function Internal Temporary Work Units Local Variable Data Storage Units Formal parameter Storage Units Number of Formal Parameters Returned Address Caller’s SP (Start Address of caller’s activation record)
/
本文档为【Ch7--Exercises】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索