C OMPUTER A RCHITECTURE & O RGANIZATION Assemblers and Compilers Engr. Umbreen Sabir Computer Engineering Department, University of Engg. & Technology.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

The University of Adelaide, School of Computer Science
Lecture 9: MIPS Instruction Set
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
Computer Architecture Lecture 7 Compiler Considerations and Optimizations.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 8 Sept 23 Completion of Ch 2 translating procedure into MIPS role of compilers, assemblers, linking, loading etc. pitfalls, conclusions Chapter.
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
CS3350B Computer Architecture Winter 2015 Lecture 4
Lecture 8: MIPS Instruction Set
The Assembly Language Level
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
Chapter 3 Loaders and Linkers
Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.
Computer Organization CS224 Fall 2012 Lesson 12. Synchronization  Two processors or threads sharing an area of memory l P1 writes, then P2 reads l Data.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
1 Lecture 5: MIPS Examples Today’s topics:  the compilation process  full example – sort in C Reminder: 2 nd assignment will be posted later today.
An introduction to systems programming
CS 61C L14Introduction to MIPS: Instruction Representation II (1) Garcia, Spring 2004 © UCB Roy Wang inst.eecs.berkeley.edu/~cs61c-tf inst.eecs.berkeley.edu/~cs61c.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Computer Architecture and Design – ECEN 350 Part 4 [Some slides adapted from M. Irwin, D. Paterson and others]
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
MIPS coding. SPIM Some links can be found such as:
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Mohamed Younis CMCS 411, Computer Architecture 1 CMCS Computer Architecture Lecture 5 Addressing Mode & Architectural Design Guidelines February.
O VERVIEW OF THE IBM J AVA J UST - IN -T IME C OMPILER Presenters: Zhenhua Liu, Sanjeev Singh 1.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
LANGUAGE SYSTEMS Chapter Four Modern Programming Languages 1.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
Lecture 5 Page 1 CS 111 Online Processes CS 111 On-Line MS Program Operating Systems Peter Reiher.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
L07 – Assemblers and Compilers 1 Comp 411 Assemblers and Compilers When I find my code in tons of trouble, Friends and colleagues come to me, Speaking.
Computer Organization and Design Assember & Compiler Montek Singh Mon, Feb 21, 2011 Lecture 7.
The Assembly Process Computer Organization and Assembly Language: Module 10.
1 Lecture 6: Assembly Programs Today’s topics:  Large constants  The compilation process  A full example  Intro to the MARS simulator.
CSc 453 Linking and Loading
Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
1 Computer Architecture & Assembly Language Spring 2001 Dr. Richard Spillman Lecture 10 –Assembly V.
Lecture 3 Translation.
Assemblers, linkers, loaders
Assembler, Compiler, MIPS simulator
Computer Architecture & Operations I
Lecture 6: Assembly Programs
Compiler Construction (CS-636)
System Programming and administration
The University of Adelaide, School of Computer Science
Compiler Construction
Machine Independent Features
Assemblers and Compilers
Computer Organization and Design Assembly & Compilation
Computer Architecture
10/6: Lecture Topics C Brainteaser More on Procedure Call
Where is all the knowledge we lost with information? T. S. Eliot
An introduction to systems programming
Lecture 4: Instruction Set Design/Pipelining
Program Assembly.
Presentation transcript:

C OMPUTER A RCHITECTURE & O RGANIZATION Assemblers and Compilers Engr. Umbreen Sabir Computer Engineering Department, University of Engg. & Technology Taxila. 20/2/2009 CA&O Lecture 7 by Engr. Umbreen Sabir 1

P ATH FROM P ROGRAMS TO B ITS 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

C OMPILERS The compiler transforms the C program into an assembly language program, a symbolic form of what the machine understands. Higher level language programs take many fewer lines of code than assembly language. So, programmer productivity is higher. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

H OW AN A SSEMBLER W ORKS Three major components of assembly 1) Allocating and initialing data storage 2) Conversion of mnemonics to binary instructions 3) Resolving addresses Pseudoinstructions: Assembler can also treat common variations of machine level instructions as if they were instructions in their own right. Such instructions are called Pseudoinstructions. e.g. Move $t0, $t1 #register $t0 gets register $t1. Assembler converts this assembly language instruction into the machine language equivalent of the following instruction: add $t0, $zero, $t1 It converts blt into two instructions slt and bne. MIPS assembler also allows 32-bit constants to be loaded into a register despite the 16-bit limit of immediate instructions. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

H OW AN A SSEMBLER W ORKS C ONT. The assembler turn the assembly language program into an object file, which is a combination of machine language instructions, data and information needed to place instructions in memory. Assembler keeps track of labels used in branches and data transfer instructions in a symbol table. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

O BJECT F ILE C OMPONENTS Object file typically contains six distinct pieces. 1. Object File Header: describes size and position of other pieces. 2. Text Segment: Contains machine code. 3. Data segment: static or dynamic data. 4. Relocation information: identifies instructions and data words that depend on absolute addresses when the program is loaded in memory. 5. Symbol Table: contains the remaining labels such as external references. 6. Debugging Information 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

E XAMPLE 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

R ESOLVING A DDRESSES - 1 ST P ASS “O LD - STYLE ” 2- PASS ASSEMBLER APPROACH 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

R ESOLVING A DDRESSES – 2 ND P ASS 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

M ODERN W AY – 1-P ASS A SSEMBLERS Modern assemblers keep more information in their symbol table which allows them to resolve addresses in a single pass. Known addresses (backward references) are immediately resolved. Unknown addresses (forward references) are “back-filled” once they are resolved. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

T HE R OLE OF A L INKER Some aspects of address resolution cannot be handled by the assembler alone. 1) References to data or routines in other object modules 2)The layout of all segments in memory 3) Support for REUSABLE code modules 4) Support for RELOCATABLE code modules This final step of resolution is the job of a LINKER 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

L INKER Also called link editor. A system program that combines independently assembled machine language programs and resolves all undefined labels into an executable file. Three steps of linker Place code and data modules symbolically in memory. Determine the addresses of data and instruction labels. Place both the internal and external references. The linker uses the relocation information and symbol table in each object module to resolve all undefined labels. The linker produces an executable file that can be run on any computer. This file has same format as object file, except that it contains no unresolved references. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

L OADER A system program that places an object program in main memory so that it is ready to execute. It follows following steps Reads the exe file header to determine size of the text and data segments. Creates an address space large enough for text and data. Copies the instructions and data from the exe to memory. Copies the parameters to the main program onto the stack. Initializes the machine registers and sets the stack pointer to the first free location. Jumps to a start-up routine that copies the parameters into the argument registers and calls the main routine of the program. Terminates program by exit system call. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

S TATIC AND D YNAMIC L IBRARIES LIBRARIES are commonly used routines stored as a concatenation of “Object files”. A global symbol table is maintained for the entire library with entry points for each routine. When routines in LIBRARIES are referenced by assembly modules, the routine’s entry points are resolved by the LINKER, and the appropriate code is added to the executable. This sort of linking is called STATIC linking. Many programs use common libraries. It is wasteful of both memory and disk space to include the same code in multiple executables. The modern alternative to STATIC linking is to allow the LOADER and THE PROGRAM ITSELF to resolve the addresses of libraries routines. This form of linking is called DYNAMIC linking (e.x..dll). 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

D YNAMICALLY L INKED L IBRARIES Library routines are not linked and loaded until the program is run. Program and library routines keep extra information on the location of nonlocal procedures and their names. In Initial version, loader ran a dynamic linker to linker, using extra information in file to find appropriate libraries but it still linked all routines of the library. Then came lazy procedure linker version of DLLs, where each routine is linked after it is called. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

D YNAMICALLY L INKED L IBRARIES 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

D YNAMICALLY L INKED L IBRARIES 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

D YNAMICALLY L INKED L IBRARIES 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

M ODERN L ANGUAGES Intermediate “object code language” Rather than compiled to assembly language, java is compiled to instructions that are easy to interpret, the Java Byte Code, A software interpreter, Java Virtual Machine (JVM) can execute java bytecodes. An interpreter is a program that simulates an instruction set architecture. E.g. MIPS simulator is an interpreter. Upside of interpreter is portability. Downside of interpreter is low performance. To preserve portability and improve performance, Just In Time (JIT) compilers were introduced, which translate while the program is running. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

M ODERN L ANGUAGES Intermediate “object code language” 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

M ODERN L ANGUAGES Intermediate “object code language” 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

C OMPILER O PTIMIZATIONS High Level Optimization Transformations that are done at something close to the source level. Local & Global Optimization Local Optimization Works within a single basic block. Global Optimization Works across multiple basic blocks. Global Register Allocation Allocates variables to registers for regions of the code. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

C OMPILER O PTIMIZATIONS Common Subexpression Elimination: Finds multiple instances of the same expression and replaces the second one by a reference to the first. Strength Reduction: Replaces complex operations by simpler ones. Constant Propagation/Constant Folding: Find constants in code and propagates them, collapsing constant values whenever possible. Copy Propagations: Propagates values that are simple copies, eliminating the need to reload values. Dead Store Elimination: Finds stores to values that are not used again and eliminates the stores. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

C OMPILER O PTIMIZATIONS Global Code Optimization Code motion Finds code that is loop invariant: a particular piece of code computes the same value on every loop iteration and may be computed once outside the loop. Induction variable elimination Combination of transformations that reduce overhead on indexing arrays, essentially replacing array indexing with pointer access. 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

C OMPILER O PTIMIZATIONS 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

C OMPILER O PTIMIZATIONS Example “C” Code: 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

U NOPTIMIZED A SSEMBLY O UTPUT With debug flags set: 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

R EGISTER A LLOCATION Assign local variables to registers 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

L OOP -I NVARIANT C ODE M OTION Assign globals to temp registers and moves assignments outside of loop 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

R EMOVE U NNECESSARY T ESTS Since “i” is initially set to “0”, we already know it is less than “10”, so why test it the first time through? 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

R EMOVE U NNECESSARY S TORES All we care about it the value of total after the loop, and simplify loop 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir

U NROLLING L OOP Two copies of the inner loop reduce the branching overhead 20/2/ CA&O Lecture 7 by Engr. Umbreen Sabir