Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Teste para ver o uso de DEC e INC
- seguinte code compilei
- gcc test2.c -o test2
- depois
- gcc test2.c -o test2 -O3
- lembrando http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
- ---
- cooler@coolerlabs:~$ cat test2.c
- #include <stdio.h>
- int
- main()
- {
- int x=10;
- while(x)
- {
- puts("ola");
- x--;
- }
- return 0;
- }
- ---
- então com "objdump -D test2" olhando o "main()"
- dump do code sem nenhuma otimização, não vi manifestação do DEC nem do INC
- acho que o esperado era "DEC" já que usamos "x--".
- ---
- 080483d4 <main>:
- 80483d4: 55 push %ebp
- 80483d5: 89 e5 mov %esp,%ebp
- 80483d7: 83 e4 f0 and $0xfffffff0,%esp
- 80483da: 83 ec 20 sub $0x20,%esp
- 80483dd: c7 44 24 1c 0a 00 00 movl $0xa,0x1c(%esp)
- 80483e4: 00
- 80483e5: eb 11 jmp 80483f8 <main+0x24>
- 80483e7: c7 04 24 e0 84 04 08 movl $0x80484e0,(%esp)
- 80483ee: e8 fd fe ff ff call 80482f0 <puts@plt>
- 80483f3: 83 6c 24 1c 01 subl $0x1,0x1c(%esp)
- 80483f8: 83 7c 24 1c 00 cmpl $0x0,0x1c(%esp)
- 80483fd: 75 e8 jne 80483e7 <main+0x13>
- 80483ff: b8 00 00 00 00 mov $0x0,%eax
- 8048404: c9 leave
- 8048405: c3 ret
- 8048406: 90 nop
- 8048407: 90 nop
- 8048408: 90 nop
- 8048409: 90 nop
- 804840a: 90 nop
- 804840b: 90 nop
- 804840c: 90 nop
- 804840d: 90 nop
- 804840e: 90 nop
- 804840f: 90 nop
- ---
- De cara nota-se loop unrolling, ou seja não vemos CMP nem JMP
- chamou o puts() e passou argumento 10vezes... uso do XOR em eax...
- ---
- 08048320 <main>:
- 8048320: 55 push %ebp
- 8048321: 89 e5 mov %esp,%ebp
- 8048323: 83 e4 f0 and $0xfffffff0,%esp
- 8048326: 83 ec 10 sub $0x10,%esp
- 8048329: c7 04 24 30 85 04 08 movl $0x8048530,(%esp)
- 8048330: e8 bb ff ff ff call 80482f0 <puts@plt>
- 8048335: c7 04 24 30 85 04 08 movl $0x8048530,(%esp)
- 804833c: e8 af ff ff ff call 80482f0 <puts@plt>
- 8048341: c7 04 24 30 85 04 08 movl $0x8048530,(%esp)
- 8048348: e8 a3 ff ff ff call 80482f0 <puts@plt>
- 804834d: c7 04 24 30 85 04 08 movl $0x8048530,(%esp)
- 8048354: e8 97 ff ff ff call 80482f0 <puts@plt>
- 8048359: c7 04 24 30 85 04 08 movl $0x8048530,(%esp)
- 8048360: e8 8b ff ff ff call 80482f0 <puts@plt>
- 8048365: c7 04 24 30 85 04 08 movl $0x8048530,(%esp)
- 804836c: e8 7f ff ff ff call 80482f0 <puts@plt>
- 8048371: c7 04 24 30 85 04 08 movl $0x8048530,(%esp)
- 8048378: e8 73 ff ff ff call 80482f0 <puts@plt>
- 804837d: c7 04 24 30 85 04 08 movl $0x8048530,(%esp)
- 8048384: e8 67 ff ff ff call 80482f0 <puts@plt>
- 8048389: c7 04 24 30 85 04 08 movl $0x8048530,(%esp)
- 8048390: e8 5b ff ff ff call 80482f0 <puts@plt>
- 8048395: c7 04 24 30 85 04 08 movl $0x8048530,(%esp)
- 804839c: e8 4f ff ff ff call 80482f0 <puts@plt>
- 80483a1: 31 c0 xor %eax,%eax
- 80483a3: c9 leave
- 80483a4: c3 ret
- 80483a5: 90 nop
- 80483a6: 90 nop
- 80483a7: 90 nop
- ---
Advertisement
Add Comment
Please, Sign In to add comment