深入理解计算机系统 - 练习题 - 第三章 (练习题3.32)

有些话、适合烂在心里 提交于 2019-12-03 13:20:55

一个C函数的fun具有如下代码体

*p  =  d;

return x - c;


执行这个函数体的IA32代码如下:

1 movsbl 12(%ebp),%edx

2 movl  16(%ebp),%eas

3 movl %edx,(%eax)

4 movswl 8(%ebp),%eax

5 movl 20(%ebp),%edx

6 subl %eax,%edx

7 movl %edx,%eax


写出函数fun的原型,给出参数p、d、x和c的类型和顺序


答案


epb是栈帧指针,参数压栈的顺序是从右到左。返回值由寄存器eax返回。

所以结合汇编代码,其解释为:

movsbl  12(%ebp),%edx //chard

movl  16(%ebp),%eax //int*p

3 movl %edx,(%eax) //*p = d

4 movswl 8(%ebp),%eax //short c

5 movl 20(%ebp),%edx //int x

6 subl %eax,%edx //x - c

7 movl %edx,%eax //int

则fun的原型为


int fun(short c, char d, int* p, int x);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!