小弟以前学过8086汇编,准确的说是看过王爽的那本书。
现在在深入学习C语言,想在linux用汇编分析一下C语言各种变量的存储位置,用gcc -S hello.c生成的汇编代码却看不大懂,下载了电子书,发现书也不能解答我的疑问,hello.s与我在网上查到的AT&T风格的汇编教程好像有一点不符啊。所以来请教一下各位高手。
hello.c的代码如下:什么没干只是定义了很多变量。
int a = 100;
short int b = 200;
int c;
short int d;
static int e = 300;
static short int f = 400;
static int g;
static short int h;
const int i = 500;
const short int j = 600;
const int k;
const short int l;
char *str = "hello world!";
int main()
{
int m = 700;
short int n = 800;
int o;
short int p;
static int q = 900;
static short int r = 1000;
const int s = 1100;
const short t = 1200;
const int u;
const short int v;
char *str2 = "hello China!";
return 0;
}
gcc -S hello.c生成的汇编代码如下:
.file "hello.c"
.globl a
.data
.align 4
.type a, @object
.size a, 4
a: ;不太理解的是a:后面应该只跟a的东西,可是根据对齐方式,发现b的东西也在下面
.long 100
.globl b;这里是b的定义了,为什么不另外抬头,难道只是gcc生成时没考虑到这一点?
.align 2
.type b, @object
.size b, 2
b:
.value 200
.comm c,4,4
.comm d,2,2
.align 4
.type e, @object
.size e, 4
e:
.long 300
.align 2
.type f, @object
.size f, 2
f:
.value 400
.local g
.comm g,4,4
.local h
.comm h,2,2
.globl i
.section .rodata
.align 4
.type i, @object
.size i, 4
i:
.long 500
.globl j
.align 2
.type j, @object
.size j, 2
j:
.value 600