[英]gcc Assembly code output different than expected
我是c和gcc的新手。 我試圖跟隨計算機系統中的一個例子:程序員的觀點。 作者說將以下代碼放入文件(code.c)
int accum = 0;
int sum(int x, int y)
{
int t = x + y;
accum += t;
return t;
}
並使用gcc如下輸出匯編代碼文件
gcc -O2 -S code.c
將生成匯編代碼如下
sum:
pushl %ebp
movl %esp,%ebp
movl 12(%ebp),%eax
addl 8(%ebp),%eax
addl %eax,accum
movl %ebp,%esp
popl %ebp
ret
但是在我的機器上(操作系統:Ubuntu 10.4 x64)我得到以下內容
.file "code.c"
.intel_syntax noprefix
.text
.p2align 4,,15
.globl sum
.type sum, @function
sum:
.LFB0:
.cfi_startproc
lea eax, [rdi+rsi]
add DWORD PTR accum[rip], eax
ret
.cfi_endproc
.LFE0:
.size sum, .-sum
.globl accum
.bss
.align 4
.type accum, @object
.size accum, 4
accum:
.zero 4
.ident "GCC: (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3"
.section .note.GNU-stack,"",@progbits
為什么我看到這種差異?
因為這本書已有11年歷史,而且自寫完以來,gcc已經發生了很大的變化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.