|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
|
[Asm/C]Asm prodotto e ottimizzazioni
questo è il sorgente C che ho compilato:
Codice:
/* ### Copyright (c) 2004 Luca Francesca ### This script is provided under the terms of the GNU General Public License ### (see http://www.gnu.org/licenses/gpl.html for the full license text.) */ #include <stdio.h> #include <stdlib.h> #define MASK 0x40 /* control bit 6 */ int main(int argc, char *argv[]) { unsigned int i = 100, tmp1 , tmp2, tmp3, tmp4; tmp1 = i & MASK; tmp2 = i ^ MASK; tmp3 = (i >> 2); tmp4 = (i << 2); printf("i = %d \n \ i & MASK = %d \n \ i ^ MASK = %d \n \ i >> 2 = %d \n\ i << 2 = %d\n", i, tmp1, tmp2, tmp3, tmp4); char c; scanf("%c", &c); return 0; } Codice:
.file "i.c" .def ___main; .scl 2; .type 32; .endef .text .align 32 LC0: .ascii "i = %d \12 i & MASK = %d \12 i ^ MASK = %d \12 i >> 1 = %d \12 i << 1 = %d\12\0" LC1: .ascii "%c\0" .align 2 .globl _main .def _main; .scl 2; .type 32; .endef _main: pushl %ebp movl %esp, %ebp subl $40, %esp andl $-16, %esp movl $0, %eax movl %eax, -28(%ebp) movl -28(%ebp), %eax call __alloca call ___main movl $100, -4(%ebp) movl -4(%ebp), %eax andl $64, %eax movl %eax, -8(%ebp) movl -4(%ebp), %eax xorl $64, %eax movl %eax, -12(%ebp) movl -4(%ebp), %eax shrl %eax movl %eax, -16(%ebp) movl -4(%ebp), %eax addl %eax, %eax movl %eax, -20(%ebp) subl $8, %esp pushl -20(%ebp) pushl -16(%ebp) pushl -12(%ebp) pushl -8(%ebp) pushl -4(%ebp) pushl $LC0 call _printf addl $32, %esp subl $8, %esp leal -21(%ebp), %eax pushl %eax pushl $LC1 call _scanf addl $16, %esp movl $0, %eax leave ret .def _scanf; .scl 2; .type 32; .endef .def _printf; .scl 2; .type 32; .endef Codice:
.file "i.c" .def ___main; .scl 2; .type 32; .endef .text .align 32 LC0: .ascii "i = %d \12 i & MASK = %d \12 i ^ MASK = %d \12 i >> 2 = %d \12 i << 2 = %d\12\0" LC1: .ascii "%c\0" .align 2 .p2align 4,,15 .globl _main .def _main; .scl 2; .type 32; .endef _main: pushl %ebp xorl %eax, %eax movl %esp, %ebp pushl %edx pushl %edx andl $-16, %esp call __alloca call ___main pushl %eax pushl %eax pushl $400 pushl $25 pushl $36 pushl $64 pushl $100 pushl $LC0 call _printf leal -1(%ebp), %edx addl $24, %esp pushl %edx pushl $LC1 call _scanf movl %ebp, %esp xorl %eax, %eax popl %ebp ret .def _scanf; .scl 2; .type 32; .endef .def _printf; .scl 2; .type 32; .endef Ora vorrei riflettere con voi su una cosa.......ma perche cìè questo divario di codice? P.S: qualcuno puo postare il codice del VC++6 e del VC++.NET per confrontare l'output?? P.P.S: se volete..chiudetemi il post.....ma secondo me è molto bello vedere le diff tra compilatori
__________________
Gnu/Linux User
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Cosa ti aspettavi scusa? Che l'ottimizzatore facesse ugualmente i calcoli, anche se poteva conoscere il risultato a priori?
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
|
la mia era curiosita
Il mio PS sarebbe motlo interessante cmq, IMHO
__________________
Gnu/Linux User
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Intanto, IO ho fatto meglio di TE
Codice:
.file "aa.c" .version "01.01" gcc2_compiled.: .section .rodata.str1.32,"ams",@progbits,1 .align 32 .LC0: .string "i = %d \n i & MASK = %d \n i ^ MASK = %d \n i >> 2 = %d \n i << 2 = %d\n" .section .rodata.str1.1,"ams",@progbits,1 .LC1: .string "%c" .text .align 16 .globl main .type main,@function main: subl $20, %esp pushl $400 pushl $25 pushl $36 pushl $64 pushl $100 pushl $.LC0 call printf addl $24, %esp leal 19(%esp), %eax pushl %eax pushl $.LC1 call scanf xorl %eax, %eax addl $28, %esp ret .Lfe1: .size main,.Lfe1-main .ident "GCC: (GNU) 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)"
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
...la mano magica
(mi scuso per le .string, ma non mi veniva in mente altro per riservare un pò di spazio Codice:
.file "aa.c" .version "01.01" gcc2_compiled.: .section .rodata.str1.32,"ams",@progbits,1 .align 32 .LC0: .string "i = %d \n i & MASK = %d \n i ^ MASK = %d \n i >> 2 = %d \n i << 2 = %d\n" .section .rodata.str1.1,"ams",@progbits,1 .text .align 16 .globl main .type main,@function main: movl %esp, (zampa) leal zumpa, %esp call printf movl (zampa), %esp ret .Lfe1: .size main,.Lfe1-main .ident "GCC: (GNU) 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)" .data .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " .string " " zumpa: .long .LC0 .long 100 .long 64 .long 36 .long 25 .long 400 zampa: .long 0
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Oct 2001
Messaggi: 11471
|
questa è la versione del 3.5
Codice:
.file "a.c" .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "i = %d \n i & MASK = %d \n i ^ MASK = %d \n i >> 2 = %d \n i << 2 = %d\n" .LC1: .string "%c" .text .align 4 .globl main .type main, @function main: pushl %ebp movl %esp, %ebp pushl %eax pushl $400 pushl $25 pushl $36 pushl $64 pushl $100 pushl $.LC0 call printf leal -1(%ebp), %eax pushl %eax pushl $.LC1 call scanf xorl %eax, %eax leave ret .size main, .-main .ident "GCC: (GNU) 3.5.0 20040724 (experimental) (Debian 3.5-0pre1)" .section .note.GNU-stack,"",@progbits |
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Battetemi questa
(oops mi ero scordato la scanf Codice:
fmt: .string "%c\0i = %d \n i & MASK = %d \n i ^ MASK = %d \n i >> 2 = %d \n i << 2 = %d\n" .globl main main: movl %esp, (zampa) leal zumpa, %esp call printf leal zompa, %esp call scanf movl (zampa), %esp ret .data zampa: .zero 4096 zumpa: .long fmt+3 .long 100 .long 64 .long 36 .long 25 .long 400 zompa: .long fmt .long zampa+4
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 Ultima modifica di ilsensine : 09-09-2004 alle 22:12. |
|
|
|
|
|
#8 | |
|
Senior Member
Iscritto dal: Oct 2001
Messaggi: 11471
|
Quote:
ciao |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 03:20.



















