|
- #include <stdlib.h>
- #include <stdio.h>
- int main()
- {
- int i=0;
- scanf("%d",&i);
- ++i;
- printf("%d\n",i);
- return 0;
- }
复制代码
原来想编译成的汇编代码中i++应该转换成inc指令的,却没想到是addl,这是怎么回事呢?
- .file "test.c"
- .section .rodata.str1.1,"aMS",@progbits,1
- .LC0:
- .string "%d"
- .LC1:
- .string "%d\n"
- .text
- .p2align 4,,15
- .globl main
- .type main, @function
- main:
- leal 4(%esp), %ecx
- andl $-16, %esp
- pushl -4(%ecx)
- pushl %ebp
- movl %esp, %ebp
- pushl %ecx
- subl $36, %esp
- leal -8(%ebp), %eax
- movl $0, -8(%ebp)
- movl %eax, 4(%esp)
- movl $.LC0, (%esp)
- call scanf
- movl -8(%ebp), %eax
- addl $1, %eax
- movl %eax, -8(%ebp)
- movl %eax, 4(%esp)
- movl $.LC1, (%esp)
- call printf
- addl $36, %esp
- xorl %eax, %eax
- popl %ecx
- popl %ebp
- leal -4(%ecx), %esp
- ret
- .size main, .-main
- .ident "GCC: (GNU) 4.2.1 (Debian 4.2.1-6)"
- .section .note.GNU-stack,"",@progbits
复制代码
编译选项是
gcc -S -O0 test.c
不过好像O4也是这个效果 |
|