所以我写了以下C代码:
#include <stdio.h>
int main() {
int i = 1;
while(i) {
printf("in loop\n");
i++;
if(i == 10) {
break;
}
}
return 0;
}
使用 gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 编译,它反汇编为:
0x000000000040051c <+0>: push %rbp
0x000000000040051d <+1>: mov %rsp,%rbp
0x0000000000400520 <+4>: sub $0x10,%rsp
0x0000000000400524 <+8>: movl $0x1,-0x4(%rbp)
0x000000000040052b <+15>: jmp 0x400541 <main+37>
0x000000000040052d <+17>: mov $0x400604,%edi
0x0000000000400532 <+22>: callq 0x4003f0 <puts@plt>
0x0000000000400537 <+27>: addl $0x1,-0x4(%rbp)
0x000000000040053b <+31>: cmpl $0xa,-0x4(%rbp)
0x000000000040053f <+35>: je 0x400549 <main+45>
0x0000000000400541 <+37>: cmpl $0x0,-0x4(%rbp)
0x0000000000400545 <+41>: jne 0x40052d <main+17>
0x0000000000400547 <+43>: jmp 0x40054a <main+46>
0x0000000000400549 <+45>: nop
0x000000000040054a <+46>: mov $0x0,%eax
0x000000000040054f <+51>: leaveq
0x0000000000400550 <+52>: retq
为什么nop
在+45上有一个?为什么je
在 +35上不直接跳到 +46?