一个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返回。
所以结合汇编代码,其解释为:
1 movsbl 12(%ebp),%edx //chard
2 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);
来源:CSDN
作者:changhai1982
链接:https://blog.csdn.net/CHANGHAI1982/article/details/7256599