- 論壇徽章:
- 0
|
回復(fù) #5 MMMIX 的帖子
對比了一下匯編后的結(jié)果,發(fā)現(xiàn)效率是一樣的,而且linux內(nèi)核中用的都是for(i=0;i<MAX;i++)這種寫法。昨天看到一個(gè)哥們的帖子也提到這個(gè)問題,說后一種寫法編譯后運(yùn)行效率高,又正好我們這邊代碼都用的后一種寫法,所以誤解了。
.file "a.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
subl $20, %esp
movl $0, -8(%ebp)
jmp .L2
.L3:
addl $1, -8(%ebp)
.L2:
cmpl $99, -8(%ebp)
jle .L3
movl $100, -8(%ebp)
jmp .L4
.L5:
subl $1, -8(%ebp)
.L4:
cmpl $0, -8(%ebp)
jg .L5
addl $20, %esp
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.3.2-1ubuntu11) 4.3.2"
.section .note.GNU-stack,"",@progbits |
|