Lesson Objectives Aims Understand how machine code is generated

Slides:



Advertisements
Similar presentations
Target Code Generation
Advertisements

P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Register Allocation CS 671 March 27, CS 671 – Spring Register Allocation - Motivation Consider adding two numbers together: Advantages: Fewer.
Lecture 8: MIPS Instruction Set
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
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++
Systems Software.
Program Representations. Representing programs Goals.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Compiled by Benjamin Muganzi 3.2 Functions and Purposes of Translators Computing 9691 Paper 3 1.
Precision Going back to constant prop, in what cases would we lose precision?
A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
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.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CIS250 OPERATING SYSTEMS Chapter One Introduction.
Introduction to OOP CPS235: Introduction.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 1 – Introduction to C.
Hello world !!! ASCII representation of hello.c.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
Lecture 3 Translation.
Topic 2: Hardware and Software
Component 1.6.
Component 1.6.
Visit for more Learning Resources
Computer Science 210 Computer Organization
Introduction to programming
Lesson Objectives Aims You should be able to:
Operating Systems (CS 340 D)
The compilation process
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
Linking & Loading.
Data Structures Interview / VIVA Questions and Answers
Swapping Segmented paging allows us to have non-contiguous allocations
CS-3013 Operating Systems C-term 2008
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
Chapter 14 Instruction Level Parallelism and Superscalar Processors
CSC 322 Operating Systems Concepts Lecture - 16: by
Computer Science 210 Computer Organization
Compiler Construction
Practice Six Chapter Eight.
Arrays and Linked Lists
MEMORY MANAGEMENT & their issues
Instruction Level Parallelism and Superscalar Processors
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
Memory Management Tasks
Lecture 30 Syed Mansoor Sarwar
Memory Management Overview
Computer Organization and Design Assembly & Compilation
Binding Times Binding is an association between two things Examples:
Programming Fundamentals Lecture #3 Overview of Computer Programming
Creating Computer Programs
Mastering Memory Modes
Software Development Environment, File Storage & Compiling
Foundations and Definitions
PROGRAM AT RUNTIME Subject code: CSCI-620
An introduction to systems programming
Target Code Generation
Creating Computer Programs
Chapter 1 Introduction to Programming
Dynamic Binary Translators and Instrumenters
SPL – PS1 Introduction to C++.
Presentation transcript:

Lesson Objectives Aims Understand how machine code is generated Understand the role of Linkers and Loaders during compilation

Machine Code Generation AST Identify Machine Code Blocks Binary Executable

The compiler will perform the following actions: Convert AST nodes in to machine code Attempt a best fit model of allocating registers Machine code optimisation

Converting to machine code Once code is split in to atomic elements, it becomes much easier to convert to machine code Languages all use pre-defined actions such as : Assignment Comparison Branching These can all be mapped to pre existing machine code templates

Allocation of registers During any operation, registers will be used CPU’s only contain a certain number of registers Usually, each variable will need access to a register in order to be manipulated This means the compiler must assign registers to variables and some will share registers – clashes must be avoided!

This is a non deterministic problem In other words, the “correct” answer can either never be found or is so computationally expensive you’d die before it did. Just like a sat-nav…

What kills CPU efficiency? Optimisation What kills CPU efficiency? The optimisation stage will effectively try to rework code so that cpu disruption is minimised: Removing unnecessary branches Predicting probable program flow Using any CPU extensions/specific instructions instead of “generic” code (targeted compilation)

Linking and loading Libraries are a god send Back in t’ day, you had to code EVERYTHING yourself Then there became a need for “middleware” and libraries Why?

At this point, the compiler has to make sure that the libraries are included in the final executable. These can be: Static dynamic

Linker/Loader The linker will tell your code how to access external resources Static linking is where the library is COPIED to the executable This has obvious advantages and disadvantages…

Dynamically linked libraries are just that – linked They keep file size small Can be updated without affecting the executable May not be present!

Loaders Loaders handle the connections to a dynamic library – loading them in to memory when necessary They are small utilities that handle the interaction between program and library This is because we don’t always know where in memory a dynamic library will reside

Review/Success Criteria You should know: How code goes from high level languages to an executable!