Elements of Computing Systems, Nisan & Schocken, MIT Press, www.idc.ac.il/tecs, Chapter 6: Assembler slide 1www.idc.ac.il/tecs Assembler Elements of Computing.

Slides:



Advertisements
Similar presentations
Chapter 4: Machine Language
Advertisements

Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 1: Boolean Logic slide 1www.idc.ac.il/tecs Chapter 1: Boolean.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Slide 1CPU Emulator Tutorial This program is part of the software suite that accompanies the book The Digital Core, by Noam Nisan and Shimon Schocken 2003,
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 5: Computer Architecture slide 1www.idc.ac.il/tecs Chapter.
The Elements of Computing Systems
CPSC Compiler Tutorial 9 Review of Compiler.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Chapter 6: An Introduction to System Software and Virtual Machines
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 3: Sequential Logic slide 1www.idc.ac.il/tecs Chapter 3:
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 8: VM II: Program Control slide 1www.idc.ac.il/tecs Chapter.
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 7: VM I: Stack Arithmetic slide 1www.idc.ac.il/tecs Chapter.
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Introduction: Hello, World Below slide 1www.idc.ac.il/tecs Introduction:
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 10: Compiler I: Syntax Analysis slide 1www.idc.ac.il/tecs.
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 9: High Level Language slide 1www.idc.ac.il/tecs Chapter.
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 2: Boolean Logic slide 1www.idc.ac.il/tecs Chapter 2: Boolean.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 10: Compiler I: Syntax Analysis slide 1www.idc.ac.il/tecs Compiler.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 7: Virtual Machine I: Stack Arithmetic slide 1www.nand2tetris.org.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 7: Virutal Machine, Part I slide 1www.idc.ac.il/tecs Virtual Machine.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 4: Machine Language slide 1www.idc.ac.il/tecs Machine Language.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 5: Computer Architecture slide 1www.idc.ac.il/tecs Computer Architecture.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 5: Computer Architecture slide 1www.nand2tetris.org Building a.
Slide 1/8Jack IDE Tutorial, Index This program is part of the software suite that accompanies the book The Elements of Computing.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
Slide 1/22Assembler Tutorial, Index This program is part of the software suite that accompanies the book The Elements of Computing.
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 12: Operating System slide 1www.idc.ac.il/tecs Chapter 12:
Building a Modern Computer From First Principles
Elements of Computing Systems, Nisan & Schocken, MIT Press, 2005, Chapter 11: Compiler II: Code Generation slide 1www.idc.ac.il/tecs.
Invitation to Computer Science 5 th Edition Chapter 6 An Introduction to System Software and Virtual Machine s.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 1: Boolean Logic slide 1www.nand2tetris.org Building a Modern.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 1: Boolean Logic slide 1www.idc.ac.il/tecs Boolean Logic Elements.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 2: Boolean Arithmetic slide 1www.nand2tetris.org Building a Modern.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 8: Virtual Machine, Part II slide 1www.idc.ac.il/tecs Virtual Machine.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 8: Virtual Machine, Part II slide 1www.nand2tetris.org Building.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 1: Compiler II: Code Generation slide 1www.nand2tetris.org Building.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 11: Compiler II: Code Generation slide 1www.nand2tetris.org Building.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 7: Virutal Machine, Part I slide 1www.nand2tetris.org Building.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 3: Sequential Logic slide 1www.idc.ac.il/tecs Sequential Logic.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 3: Sequential Logic slide 1www.nand2tetris.org Building a Modern.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 10: Compiler I: Syntax Analysis slide 1www.nand2tetris.org Building.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 10: Compiler I: Syntax Analysis slide 1www.nand2tetris.org Building.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 9: High-Level Language slide 1www.nand2tetris.org Building a Modern.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Building a Modern Computer From First Principles
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 7: Virutal Machine, Part I slide 1www.nand2tetris.org Building.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 1www.nand2tetris.org Building a Modern Computer.
Processor Fundamentals Assembly Language. Learning Objectives Show understanding of the relationship between assembly language and machine code, including.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 4: Machine Language slide 1www.nand2tetris.org Building a Modern.
©SoftMoore ConsultingSlide 1 Structure of Compilers.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 4: Machine Language slide 1www.nand2tetris.org Building a Modern.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Invitation to Computer Science 6th Edition
Introduction: From Nand to Tetris
Virtual Machine Part I: Stack Arithmetic
课程名 编译原理 Compiling Techniques
Chapter 1: Introduction to Compiling (Cont.)
Virtual Machine Emulator Tutorial
Compiler I: Sytnax Analysis
Compiler 薛智文 TH 6 7 8, DTH Spring.
CSE401 Introduction to Compiler Construction
Compiler 薛智文 TH 6 7 8, DTH Spring.
Processor Fundamentals
Compiler 薛智文 M 2 3 4, DTH Spring.
Presentation transcript:

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 1www.idc.ac.il/tecs Assembler Elements of Computing Systems, Nisan & Schocken, MIT Press Usage and Copyright Notice: Copyright 2005 © Noam Nisan and Shimon Schocken This presentation contains lecture materials that accompany the textbook “The Elements of Computing Systems” by Noam Nisan & Shimon Schocken, MIT Press, We provide both PPT and PDF versions. The book web site, features 13 such presentations, one for each book chapter. Each presentation is designed to support about 3 hours of classroom or self-study instruction. You are welcome to use or edit this presentation as you see fit for instructional and non- commercial purposes. If you use our materials, we will appreciate it if you will include in them a reference to the book’s web site. If you have any questions or comments, you can reach us at

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 2www.idc.ac.il/tecs Where we are at: Assembler Chapter 6 H.L. Language & Operating Sys. abstract interface Compiler Chapters VM Translator Chapters Computer Architecture Chapters Gate Logic Chapters Electrical Engineering Physics Virtual Machine abstract interface Software hierarchy Assembly Language abstract interface Hardware hierarchy Machine Language abstract interface Hardware Platform abstract interface Chips & Logic Gates abstract interface Human Thought Abstract design Chapters 9, 12

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 3www.idc.ac.il/tecs Why care about assemblers? Because … Assemblers employ nifty programming tricks Assemblers are the first rung up the software hierarchy ladder An assembler is a translator of a simple language Writing an assembler = good practice for writing compilers.

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 4www.idc.ac.il/tecs Program translation The program translation challenge Parse the source program, using the syntax rules of the source language Re-express the program’s semantics using the syntax rules of the target language Assembler = simple translator Translates each assembly command into one or more machine instructions Handles symbols ( i, sum, LOOP, END, …). Source code Translator Target code

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 5www.idc.ac.il/tecs In low level languages, symbols are used to code: Variable names Destinations of goto commands (labels) Special memory locations The assembly process: First pass: construct a symbol table Second pass: translate the program, using the symbol table for symbols resolution. Symbol resolution

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 6www.idc.ac.il/tecs Perspective This example is based on some simplifying assumptions: Largest possible program is 1024 commands long Each command fits into one memory location Each variable fits into one memory location Every one of these assumptions can be relaxed easily.

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 7www.idc.ac.il/tecs The Hack assembly language Assembly program = a stream of text lines, each being one of the following: Instruction: A-instruction or C-instruction Symbol declaration: (symbol) Comment or white space: // comment.

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 8www.idc.ac.il/tecs Handling A-instructions Translation to binary: If value is a number: simple If value is a symbol: later.

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 9www.idc.ac.il/tecs Handling C-instruction Translation to binary: simple!

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 10www.idc.ac.il/tecs The overall assembly logic For each (real) command Parse the command, i.e. break it into its constituent fields Replace each symbolic reference (if any) with the corresponding memory address (a binary number) For each field, generate the corresponding binary code Assemble the binary codes into a complete machine instruction.

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 11www.idc.ac.il/tecs Symbols handling (in the Hack language) Label symbols: The pseudo-command (label) declares that the user-defined symbol label should refer to the memory location holding the next command in the program Variable symbols: If label appears in command, and label is neither predefined nor defined elsewhere in the program using the (label) pseudo command, then label is treated as a variable Design decision: variables are mapped to consecutive memory locations starting at RAM address 16. Predefined symbols: (don’t appear in this example)

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 12www.idc.ac.il/tecs Example

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 13www.idc.ac.il/tecs Proposed implementation An assembler program can be implemented as follows. Software modules: Parser: Unpacks each command into its underlying fields Code: Translates each field into its corresponding binary value SymbolTable: Manages the symbol table Main: Initializes I/O files and drives the show. Proposed implementation stages Stage I: Build a basic assembler for programs with no symbols Stage II: Extend the basic assembler with symbol handling capabilities.

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 14www.idc.ac.il/tecs Parser module

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 15www.idc.ac.il/tecs Parser module (cont.)

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 16www.idc.ac.il/tecs Code module

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 17www.idc.ac.il/tecs Building the final assembler Initialization: create the symbol table and initialize it with the pre-defined symbols First pass: march through the program without generating any code. For each label declaration of the form ” (label) ”, add the pair to the symbol table Second pass: march again through the program, and translate each line: If the line is a C-instruction, simple If the line is ” where label is a number, simple If the line is ” and label is a symbol, look it up in the symbol table and proceed as follows:  If the symbol is found, replace it with its numeric meaning and complete the command’s translation  If the symbol is not found, then it must represent a new variable: add the pair to the symbol table, where n is the next available RAM address, and complete the command’s translation. (The allocated RAM addresses are running, starting at address 16).

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 18www.idc.ac.il/tecs Symbol table

Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 19www.idc.ac.il/tecs Perspective Simple machine language, simple assembler Most assemblers are not stand-alone, but rather encapsulated in a translator of a higher order Low-level C programming (e.g. for real-time systems) may involve some assembly programming (e.g. for optimization) Macro assemblers: