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

Slides:



Advertisements
Similar presentations
Architecture Chapter 2 - Supplement Additional Features In Chapter 2.
Advertisements

1 Homework / Exam Turn in mp2 at start of class today Reading –PAL, pp 3-6, Exam #1 next class –Open Book / Open Notes –NO calculators or other.
University of Washington Last Time For loops  for loop → while loop → do-while loop → goto version  for loop → while loop → goto “jump to middle” version.
Machine-Level Programming I: Introduction Topics Assembly Programmer’s Execution Model Accessing Information Registers Memory Arithmetic operations CS.
Machine-Level Programming II: Control Flow Today Condition codes Control flow structures Next time Procedures.
Machine-Level Programming III: Procedures Apr. 17, 2006 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables CS213.
Lecture Notes from Randal E. Bryant, CMU CS:APP Chapter 4 Computer Architecture Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction.
Machine-Level Programming III: Procedures Jan 30, 2003
Instruction Set Architecture CSC 333. – 2 – Instruction Set Architecture Assembly Language View Processor state Registers, memory, … Instructions addl,
Machine-Level Programming I: Introduction Apr. 14, 2008 Topics Assembly Programmer’s Execution Model Accessing Information Registers Memory Arithmetic.
Compiler Construction
Stack Activation Records Topics IA32 stack discipline Register saving conventions Creating pointers to local variables February 6, 2003 CSCE 212H Computer.
Recitation 2: Assembly & gdb Andrew Faulring Section A 16 September 2002.
Machine-Level Programming 3 Control Flow Topics Control Flow Switch Statements Jump Tables.
Y86 Processor State Program Registers
64-Bit Architectures Topics 64-bit data New registers and instructions Calling conventions CS 105 “Tour of the Black Holes of Computing!”
University of Washington x86 Programming III The Hardware/Software Interface CSE351 Winter 2013.
University of Washington Today More on procedures, stack etc. Lab 2 due today!  We hope it was fun! What is a stack?  And how about a stack frame? 1.
Fabián E. Bustamante, Spring 2007 Machine-Level Programming III - Procedures Today IA32 stack discipline Register saving conventions Creating pointers.
Recitation 2 – 2/11/02 Outline Stacks & Procedures Homogenous Data –Arrays –Nested Arrays Mengzhi Wang Office Hours: Thursday.
Assembly תרגול 5 תכנות באסמבלי. Assembly vs. Higher level languages There are NO variables’ type definitions.  All kinds of data are stored in the same.
Machine-Level Programming 3 Control Flow Topics Control Flow Switch Statements Jump Tables.
Machine-Level Programming 1 Introduction Topics Assembly Programmer’s Execution Model Accessing Information Registers Memory Arithmetic operations.
1 Procedure Call and Array. 2 Outline Data manipulation Control structure Suggested reading –Chap 3.7, 3.8.
University of Washington x86 Programming I The Hardware/Software Interface CSE351 Winter 2013.
Recitation 2 – 2/4/02 Outline Floating Point Typecasting
Recitation 2 – 2/11/02 Outline Stacks & Procedures Homogenous Data –Arrays –Nested Arrays Structured Data –struct s / union s –Arrays of structs.
IA32 Stack –Region of memory managed with stack discipline –Grows toward lower addresses –Register %esp indicates lowest stack address address of top element.
IA32: Control Flow Topics –Condition Codes Setting Testing –Control Flow If-then-else Varieties of Loops Switch Statements.
Machine-Level Programming 2 Control Flow Topics Condition Codes Setting Testing Control Flow If-then-else Varieties of Loops Switch Statements.
A job ad at a game programming company
Reading Condition Codes (Cont.)
Machine-Level Programming 2 Control Flow
X86 Assembly, and C-to-assembly
Conditional Branch Example
Recitation 2 – 2/11/02 Outline Stacks & Procedures
Aaron Miller David Cohen Spring 2011
Homework In-line Assembly Code Machine Language
Recitation 2 – 2/4/01 Outline Machine Model
Assembly Language Programming V: In-line Assembly Code
Machine-Level Programming II: Arithmetic & Control
Machine-Level Programming II Control Flow Sept. 9, 1999
Chapter 3 Machine-Level Representation of Programs
Machine-Level Representation of Programs II
Machine-Level Programming 1 Introduction
Computer Architecture adapted by Jason Fritts then by David Ferry
asum.ys A Y86 Programming Example
Y86 Processor State Program Registers
Instructors: Majd Sakr and Khaled Harras
Machine-Level Programming 4 Procedures
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Instructor: David Ferry
Condition Codes Single Bit Registers
3.5 Conditional Codes Spring, 2015 Euiseong Seo
Machine-Level Programming 2 Control Flow
Machine-Level Programming 2 Control Flow
Machine-Level Programming III: Procedures Sept 18, 2001
Machine-Level Representation of Programs III
Machine-Level Programming 2 Control Flow
Machine-Level Programming: Introduction
Machine-Level Representation of Programs II
Chapter 3 Machine-Level Representation of Programs
Machine-Level Programming II: Control Flow
C structures and Compilation to IA32
X86 Assembly - Control.
Machine-Level Programming II: Control Flow Sept. 12, 2007
Compiler Construction CS 606 Sohail Aslam Lecture 1.
Presentation transcript:

Compiladores I- 1 - COMPARACION PROGRAMA FUENTE Y ENSAMBLADOR GENERADO

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; }

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]); }

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

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

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

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

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