寫以下兩個無限迴圈程式:
main() {
for(;;);
} // main()
和
main() {
while(1);
} // main()
存檔後,兩個程式透過GCC(註1)翻譯成Assembly Language(註2)後的結果都是下面的結果:
.file "infinite.c"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
.L2:
jmp .L2
.size main, .-main
.ident "GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)"
.section .note.GNU-stack,"",@progbits
故兩種control statement都一樣快。
註1:不同的compiler轉譯出來的結果可能會不同。
註2:翻譯出來的組合語言是遵守AT&T syntax,跟Intex和Microsoft不太一樣!
0 意見:
張貼留言