Presentation is loading. Please wait.

Presentation is loading. Please wait.

Compiladores I- 1 - COMPARACION PROGRAMA FUENTE Y ENSAMBLADOR GENERADO.

Similar presentations


Presentation on theme: "Compiladores I- 1 - COMPARACION PROGRAMA FUENTE Y ENSAMBLADOR GENERADO."— Presentation transcript:

1 Compiladores I- 1 - COMPARACION PROGRAMA FUENTE Y ENSAMBLADOR GENERADO

2 Compiladores I- 2 - Programa Fuente #include void *malloc(); struct CharNode { char c; struct CharNode *Sig; }; struct CharNode *Append(struct CharNode *l1,struct CharNode *l2) { if (l1==NULL) return l2; else { struct CharNode *tmp; tmp=malloc(sizeof (struct CharNode)); tmp->c=l1->c; tmp->Sig=Append(l1->Sig,l2); return tmp; } void PrintCharNode(struct CharNode *cn) { while (cn) { putchar(cn->c); cn=cn->Sig; }

3 Compiladores I- 3 - Programa Fuente struct CharNode *StrToCharNode(char *Str) { struct CharNode *cn; if (!*Str) return NULL; cn=malloc(sizeof (struct CharNode)); switch (*Str) { case '\\': ++Str; cn->c=*Str++; break; default: if (*Str>='a' && *Str c=*Str++ - 'a' + 'A'; else cn->c=*Str++; } cn->Sig=StrToCharNode(Str); return cn; } void main() { float Loteria[10][20]; int rnd,i,j; struct CharNode *a=StrToCharNode("Bon Nadal i "); struct CharNode *b=StrToCharNode("Bon Any Nou."); PrintCharNode(a); puts(""); PrintCharNode(Append(a,b)); for (i=0;i<10;++i) { for (j=0;j<20;++j) { rnd=(rnd*255+48) % 65536; Loteria[i][j]=rnd; } printf("\nEl gordo es %f\n",Loteria[rnd % 10][rnd % 20]); }

4 Compiladores I- 4 - Programa Compilado (append).file "code.c" gcc2_compiled.:.text.align 2.globl _Append _Append: pushl %ebp movl %esp,%ebp subl $4,%esp cmpl $0,8(%ebp) jne L2 movl 12(%ebp),%eax jmp L1.align 2,0x90 jmp L3.align 2,0x90 L2: pushl $8 call _malloc addl $4,%esp movl %eax,-4(%ebp) movl -4(%ebp),%eax movl 8(%ebp),%edx movb (%edx),%cl movb %cl,(%eax) pushl 12(%ebp) movl 8(%ebp),%eax pushl 4(%eax) call _Append addl $8,%esp movl %eax,%eax movl -4(%ebp),%edx movl %eax,4(%edx) movl -4(%ebp),%eax jmp L1.align 2,0x90 L3: L1: leave ret.align 2

5 Compiladores I- 5 - Programa Compilado (PrintCharNode).align 2.globl _PrintCharNode _PrintCharNode: pushl %ebp movl %esp,%ebp nop L5: cmpl $0,8(%ebp) je L6 decl __iob+20 cmpl $0,__iob+20 jl L7 movl __iob+24,%eax movl 8(%ebp),%edx movb (%edx),%cl movb %cl,(%eax) incl __iob+24 jmp L8.align 2,0x90 L7: pushl $__iob+20 movl 8(%ebp),%eax movsbl (%eax),%edx pushl %edx call __flsbuf addl $8,%esp L8: movl 8(%ebp),%eax movl 4(%eax),%ecx movl %ecx,8(%ebp) jmp L5.align 2,0x90 L6: L4: leave ret

6 Compiladores I- 6 - Programa Compilado (StrToCharNode).align 2.globl _StrToCharNode _StrToCharNode: pushl %ebp movl %esp,%ebp subl $4,%esp movl 8(%ebp),%eax cmpb $0,(%eax) jne L10 xorl %eax,%eax jmp L9.align 2,0x90 L10: pushl $8 call _malloc addl $4,%esp movl %eax,-4(%ebp) movl 8(%ebp),%eax movb (%eax),%dl cmpb $92,%dl je L12 jmp L13.align 2,0x90 L12:incl 8(%ebp) movl -4(%ebp),%eax movl 8(%ebp),%edx movb (%edx),%cl movb %cl,(%eax) incl 8(%ebp) jmp L11.align 2,0x90 L13:movl 8(%ebp),%eax cmpb $96,(%eax) jle L14 movl 8(%ebp),%eax cmpb $122,(%eax) jg L14 movl -4(%ebp),%eax movl 8(%ebp),%edx movb (%edx),%cl addb $-32,%cl movb %cl,(%eax) incl 8(%ebp) jmp L15.align 2,0x90 L14:movl -4(%ebp),%eax movl 8(%ebp),%edx movb (%edx),%cl movb %cl,(%eax) incl 8(%ebp) L15: L11:pushl 8(%ebp) call _StrToCharNode addl $4,%esp movl %eax,%eax movl -4(%ebp),%edx movl %eax,4(%edx) movl -4(%ebp),%eax jmp L9.align 2,0x90 L9:leave ret

7 Compiladores I- 7 - Programa Compilado (main I) LC0:.ascii "Bon Nadal i \0" LC1:.ascii "Bon Any Nou.\0" LC2:.ascii "\0" LC3:.ascii "\12El gordo es %f\12\0".align 2.globl _main _main: pushl %ebp movl %esp,%ebp subl $828,%esp pushl %esi pushl %ebx call ___main pushl $LC0 call _StrToCharNode addl $4,%esp movl %eax,-816(%ebp) pushl $LC1 call _StrToCharNode addl $4,%esp movl %eax,-820(%ebp) pushl -816(%ebp) call _PrintCharNode addl $4,%esp pushl $LC2 call _puts addl $4,%esp pushl -820(%ebp) pushl -816(%ebp) call _Append addl $8,%esp movl %eax,-824(%ebp) pushl -824(%ebp) call _PrintCharNode addl $4,%esp movl $0,-808(%ebp) L18: cmpl $9,-808(%ebp) jg L19 movl $0,-812(%ebp) L21: cmpl $19,-812(%ebp) jg L22 movl -804(%ebp),%edx movl %edx,-824(%ebp) sall $8,%edx movl %edx,-828(%ebp) movl -824(%ebp),%esi subl %esi,-828(%ebp) movl -828(%ebp),%eax addl $48,%eax movl %eax,-824(%ebp) movl %eax,-828(%ebp) cmpl $0,-828(%ebp) jge L24 addl $65535,-828(%ebp) L24: movl -828(%ebp),%edx sarl $16,%edx movl %edx,-804(%ebp) movl -804(%ebp),%esi movl %esi,-828(%ebp) movl %esi,%ecx

8 Compiladores I- 8 - Programa Compilado (main I) sall $16,%ecx movl -824(%ebp),%eax subl %ecx,%eax movl %eax,-804(%ebp) movl -808(%ebp),%edx movl %edx,-828(%ebp) sall $2,%edx movl %edx,-824(%ebp) movl -828(%ebp),%esi addl %esi,-824(%ebp) sall $4,-824(%ebp) movl -824(%ebp),%eax addl %ebp,%eax movl %eax,-828(%ebp) addl $-800,%eax movl %eax,-824(%ebp) movl -812(%ebp),%edx movl %edx,-828(%ebp) fildl -804(%ebp) fstps (%eax,%edx,4) L23: incl -812(%ebp) jmp L21.align 2,0x90 L22: L20: incl -808(%ebp) jmp L18.align 2,0x90 L19:movl -804(%ebp),%esi movl %esi,-824(%ebp) movl -824(%ebp),%eax movl $10,%esi cltd idivl %esi movl %edx,%ecx movl %eax,-828(%ebp) leal 0(,%ecx,4),%eax movl %eax,-824(%ebp) addl %ecx,-824(%ebp) sall $4,-824(%ebp) movl -824(%ebp),%edx addl %ebp,%edx movl %edx,-828(%ebp) addl $-800,%edx movl %edx,-824(%ebp) movl -804(%ebp),%ebx movl %ebx,%eax movl $20,%esi cltd idivl %esi movl %edx,%ecx movl %eax,-828(%ebp) movl -824(%ebp),%eax flds (%eax,%ecx,4) subl $8,%esp fstpl (%esp) pushl $LC3 call _printf addl $12,%esp L17: leal -836(%ebp),%esp popl %ebx popl %esi leave ret


Download ppt "Compiladores I- 1 - COMPARACION PROGRAMA FUENTE Y ENSAMBLADOR GENERADO."

Similar presentations


Ads by Google