1 / 15

6. Program Translation

6. Program Translation. CS100: The World of Computing John Dougherty Haverford College. Overview. The Problem The “Source” – high-level code The Target – low-level (machine) code Types of translation The translation algorithm/process PIPPIN. The Problem.

jmagnuson
Download Presentation

6. Program Translation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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)

  12. PIPPIN instruction layout opcode operand Each box contains a byte

  13. Sample PIPPIN Opcodes

  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)

More Related