标签:class a* amp -o cal ext format text ima
参考文章:
(1)x86-64指令系统过程调用学习笔记 https://blog.csdn.net/weixin_44735312/article/details/89818907
创建文本sum.c并编写如下程序:
#include <stdio.h>
int sum(int x,int y){
int t = x +y;
return t;
}
通过如下命令生成sum.o文件。
gcc -O2 -c sum.c
通过如下命令查看在x86-64平台上的机器指令:
objdump -d sum.o
最终的机器指令如下:
sum.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <sum>: 0: 8d 04 37 lea (%rdi,%rsi,1),%eax 3: c3 retq
lea传输源操作数偏移(而不是值)到目的寄存器。源操作数必须为内存操作数,目的寄存器必须为同一寄存器。
创建fun.c文件,内容如下:
long caller(){
char a = 1;
short b = 2;
int c = 3;
long d = 4;
callee(a,&a,b,&b,c,&c,d,&d);
return a*b + c*d;
}
void callee(char a,char* ap,short b,short* bp,int c,int* cp,long d,long* dp){
*ap += a;
*bp += b;
*cp += c;
*dp += d;
}
生成的机器码如下:

标签:class a* amp -o cal ext format text ima
原文地址:https://www.cnblogs.com/mazhimazhi/p/11290793.html