Presentation is loading. Please wait.

Presentation is loading. Please wait.

6. Program Translation CS100: The World of Computing John Dougherty Haverford College.

Similar presentations


Presentation on theme: "6. Program Translation CS100: The World of Computing John Dougherty Haverford College."— Presentation transcript:

1 6. Program Translation CS100: The World of Computing John Dougherty Haverford College

2 Overview  The Problem  The “Source” – high-level code  The Target – low-level (machine) code  Types of translation  The translation algorithm/process  PIPPIN

3 The Problem  People communication in ambiguous, high- level languages, using experience, context, and can ask for clarity interactively e.g., Thoreau threw through the tunnel.  Machines have no “sense” of context or experience, and need unambiguous instructions

4 The Source  High-level programming languages close to natural language (but not quite) Alice, Javascript, C++, Java, C#  Known as Source code  Each instructions implies many lower-level instructions (as we’ll see …)

5 The Target  Low-level instructions that are clear and simple – typically fixed in size, with a command and some reference to data Opcode Operand  Known as … Machine code || binary code || executable

6 Program Translation  From High- to Low-Level  Recall “divide and conquer” in programming Input  Process  Output … then details of Process, then details of …  Typically many low-level operations per high-level instruction  From source code to machine/binary code  Two ways to translate …

7 Interpretation  Works with the source always  Translates and executes “on the fly”  Like a language translator at the UN  Easier to debug  Executes slower

8 Compilation  Works with executable  Translates the entire program from source to machine code once  Executes the machine code as many times as needed  Recompile often during development  Executes substantially faster  Most software is distributed (except open source)  Hides algorithm

9 Phases of Translation  Scanning – breaking text sequence into tokens (i.e., meaningful chunks) “ while ”, “ = ”, “ For all together ”  Parsing – organizing the tokens to discover the meaning of the program  Code Generation – writing the sequence of machine level operations Opcodes, operands

10 Language Levels  High-level: one-to-many relation to machine language (e.g., z = x + y is 4 PIPPIN ops)  Assembly language: one-to-one (roughly) relation to machine language (PIPPIN)  Low-level: machine, or binary, language of 0s and 1s

11 Arithmetic Instructions  To demonstrate this process, we’ll look at standard arithmetic expressions and statements in a high-level language  Expressions have a pattern, or (recursively- defined) form Var = exp Where exp = value | exp + exp | exp – exp | … (demonstration of Rosetta)Rosetta

12 PIPPIN instruction layout opcodeoperand Each box contains a byte

13 Sample PIPPIN Opcodes 00000100LOD (load from X) 00000101STO (store to X) 00001111HLT (halt execution) 00000000ADD (acc = acc + X)

14 Example PIPPIN program ; PIPPIN code for Z = X + Y [1]LOD X; acc <= X [2]ADD Y; acc <= acc + Y [3]STO Z; acc => Z [4]HLT; halt ;other examples AE pp. 252-4

15 Programming Paradigms  Imperative: procedures as abstractions, details of how to do a task (e.g., FORTRAN, Pascal)  Functional: mathematical approach of input- process-return value – functions can be composed of other functions (including themselves), and can be evaluated (e.g., LISP)  Declarative: describe the information, but not the way it is processed (e.g., Prolog)  Object-Oriented: interacting objects (e.g., Java, C++, C#, Smalltalk, Javascript, Alice)


Download ppt "6. Program Translation CS100: The World of Computing John Dougherty Haverford College."

Similar presentations


Ads by Google