1 / 37

Introduction to Computer Science CSCI 150 Section 002 Session 23

Introduction to Computer Science CSCI 150 Section 002 Session 23. Dr. Richard J. Bonneau IONA Technologies Rich.Bonneau@iona.com. Today’s Outline. Today’s ‘notices’ Tonight’s Topics Review of Last Session - last of digital circuits Chapter 8 topics

caitir
Télécharger la présentation

Introduction to Computer Science CSCI 150 Section 002 Session 23

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. Introduction to Computer ScienceCSCI 150 Section 002Session 23 Dr. Richard J. Bonneau IONA Technologies Rich.Bonneau@iona.com CSCI 150: Introduction to Computer Science - Session 23

  2. Today’s Outline • Today’s ‘notices’ • Tonight’s Topics • Review of Last Session - last of digital circuits • Chapter 8 topics • Computer Architecture - the P88 computer! • Chapter 9 topics – very briefly … • Language Translation • Next Class Topics • HTML – Hyper Text Markup Language • Web Pages – constructed from HTML • Lab session with lab exercises at the end CSCI 150: Introduction to Computer Science - Session 23

  3. Today’s Notices • Office Swords 339 • Extension 2284 • Office hours Tu-Th 4-6:30 and after class • No class on Thursday – Easter Break • Homework 7 Grading Status ??? – “not till after Easter Break” - Kyle • Homework 8 Due Week from Thursday • Today’s “Pascal programs” can be found on Web Site … • Handout on “Programming the P88 Architecture” – also on web site • CEF Survey – a week from Thursday – April 24th • Final Exam – Saturday May 3rd – 2:30 – in Haberlin Lab 408 – change of room!! CSCI 150: Introduction to Computer Science - Session 23

  4. Summary of Last Session • Simple - non-arithmetic circuits - select/mux • Can be used select/move data from one place to another • Also translate controls into specific individual, exclusive signals • Sequential circuits • clocks/pulsers • scopes and waveforms • latches - to hold state of data - I.e. 1 or 0 ! • registers = collections of latches • types of memory as an addressable set of registers • Interesting circuits – never got to see them … • using supplied circuit elements and circuits from Circuit Maker’s library • input devices, animation, cars and rockets … CSCI 150: Introduction to Computer Science - Session 23

  5. Outline of Chapters 8 & 9 - Machine Architecture and Language Translation • Machine Architecture - Chapter 8 • Let’s Build A Computer • A Sample Architecture: The P88 Machine • Programming the P88 Machines • Language Translation - Chapter 9 • Enabling the Computer to Understand Pascal • Syntactic Production Rules • Attaching Semantics to the Rules • The Semantics of Pascal • The Translation of Looping Programs • (Not to be covered) • Programming Languages Overview (if time allows!) CSCI 150: Introduction to Computer Science - Session 23

  6. Machine Architecture - Chapter 8 • Let’s Build A Computer!! • A Sample Architecture: The P88 Machine • Programming the P88 Machine CSCI 150: Introduction to Computer Science - Session 23

  7. Let Us Build A Computer • CPU - Central Processing Unit • Computational registers • Instruction Register • Decoding circuitry - to select correct operations • Memory accessing circuitry • Memory • No brains - just a lot of bits! And addressing! • Stores two kinds of information • Data - used as variables in programs … • Instructions - the ‘program’ to be executed • Architectural Considerations • How many and how specialized are the computational registers? • How many and what types of instructions? • How complicated is memory access? • Speed of operation of the processor? • Multiple CPU’s - a parallel architecture?? CSCI 150: Introduction to Computer Science - Session 23

  8. The P88 Machine • A Simple machine architecture - the P88 computer! • Only one (computational) register for data manipulation - AX • Only 12 total instructions! • Instruction register - IR • Program counter - aka Instruction Pointer (IP) • Also condition flag register (CF) – used for remembering comparisons • <See architecture diagram on p. 260 and next slide> • Assumptions • Use assembly language and not binary for instructions • We will use the P88 program to show what is actually happening inside the computer! As it is executing! CSCI 150: Introduction to Computer Science - Session 23

  9. Code Deciphering Circuits Computation Circuitry Instruction Pointer Register IP IN OUT IR Instruction Register COPY Memory Only one Path activated - A Multiplexer?? . . . . . . ADD Condition Flags Register CF Computation Register AX Computer Organization - CPU Address Instruction in Memory CSCI 150: Introduction to Computer Science - Session 23

  10. A Sample Architecture: The P88 Machine • Architectural components of the P88 • Instruction pointer register - IP • Instruction register - IR • Condition Flag - CF • Computational Register - AX • Memory with addressing logic • Sneak Preview of Simulator Program: COMP1 • For major hardware components • (Use Alt-Enter to get full screen display) } CPU CSCI 150: Introduction to Computer Science - Session 23

  11. BASIC EXECUTION CYCLE OF P88 MACHINE • (1 - Fetch) • Find instruction in memory at the address currently in the IP register. • Take the instruction at that address in memory and load it into the IR. • Increment the IP to the address of the next instruction • (2 - Execute) • Execute whatever instruction is now in IR • (3 - Loop back to fetch step again) • A never ending loop - the fetch-execute cycle - classic computer design • Note that an instruction might modify IP !! I.e. a Jump instruction!! Steps managed By the clock Circuit !! CSCI 150: Introduction to Computer Science - Session 23

  12. P88 Simulator(s) • Programs COMP1 and COMP2 - available on the course web site at:http://mathcs.holycross.edu/~rbonneau/CourseFiles/P88 • Able to compile a subset of pascal into assembly language • only supports integer vars = so no declarations needed! • Execute assembly language program visually - showing instructions, registers, and memory interactions! • Has the Pascal IDE Environment look/feel! CSCI 150: Introduction to Computer Science - Session 23

  13. P88 (COMP1) Program Interface Pascal Source Assembly Language Code In Memory Data in Memory CPU Registers CPU Execution state CSCI 150: Introduction to Computer Science - Session 23

  14. First simulator run! • Let’s try it using on the NUMBER.PAS source file: begin a := (5 + 6); end • How? (Steps in doing P88 software development) • Load the P-Pascal program • Compile it • Examine the assembly language • Then execute it instruction by instruction, fetch/execute by fetch/execute – use function key F9 • Observe all the registers and memory as computer executes • Only two assembly instructions needed now • COPY dest, source where one is a register and one is memory location – copies data from the source to the destination • ADD AX,source – adds data from a source memory address location to current contents of accumulator register with result staying in the accumulator CSCI 150: Introduction to Computer Science - Session 23

  15. Programming the P88 Machine • Let’s now examine the full P88 Machine Instruction Set (see page 265 and handout) • General Classes of instructions • load/store data: COPY (between memory and accumulator) • arithmetic: ADD, SUB, MULT, DIV • comparison: CMP - (between memory and accumulator) sets the CF register • ‘jump’ : JMP, JB, JNB these can change the IP!! can test the CF • input/output: IN OUT - interaction with outside world CSCI 150: Introduction to Computer Science - Session 23

  16. Copy Instructions • Data flows between memory and CPU through the COPY instructions • Two variants:COPY AX,<memory address> AX <--(memory) means load FROM memory into AX registerCOPY <memory address>,AX AX --> (memory) means store AX contents to memory location • In both cases, COPY <dest>,<source> data moves from source to destination CSCI 150: Introduction to Computer Science - Session 23

  17. Arithmetic Instructions • Implement the 4 major arithmetic operations on integer information • All start with one piece of data already in AX and the other piece of data in memory • Result always ends up in AX Assembly Instruction Operation PerformedADD AX,<memory> AX := AX + (memory value)SUB AX,<memory> AX := AX - (memory value)MUL AX,<memory> AX := AX * (memory value)DIV AX,<memory> AX := AX / (memory value) DIV is the same as Pascal Integer Divide operation – integer result only CSCI 150: Introduction to Computer Science - Session 23

  18. Compare Instruction • Only one instruction • Compares the current contents of the accumulator register (AX) with a memory location • Will set value of the condition flag (CF) register depending on result Assembly Instruction Operation PerformedCMP AX,<memory> If AX<(memory) then CF = B else CF = NB CF Register Value: B = Memory is Bigger than AX NB = Memory is NOT Bigger CSCI 150: Introduction to Computer Science - Session 23

  19. Jump Instructions • Three instructions in this class: First is unconditional, other two are conditional • First: Unconditional Jump InstructionJMP <label> Load addr of <label> into IP reg(Note label is attached to another line of code in the program) • Next: Conditional Jump InstructionsJB <label> If CF = B then <label> -> IPJNB <label> If CF = NB then <label> -> IP CSCI 150: Introduction to Computer Science - Session 23

  20. Input/Output Instructions • Two instructions - one for input and one for output • Input instructionIN AX Read integer from user and store into AX • Output instructionOUT AX Print the contents of AX to user’s display CSCI 150: Introduction to Computer Science - Session 23

  21. Observations about P88 instructions • A very simplified set of operations - most architectures have quite a few more instructions (e.g. procedure calls, etc.) and complex memory addressing options • The accumulation register AX gets used in almost all operations - ‘where all the action is’! • The only instructions that affect the flow of execution (I.e. the IP register) are the Jump instructions (can use these to implement looping, as we will see) CSCI 150: Introduction to Computer Science - Session 23

  22. Simple assembly language code • Simple assembly language sequence: Input, Add two numbers, output to user • IN AX ; input number from user into AX • COPY a,AX ; store into location labeled a • IN AX ; input another number from user • COPY b,AX ; store into location labeled b • COPY AX,a ; load location a into AX register • ADD AX,b ; add location b to value in AX • COPY c,AX ; store sum into location labeled c • COPY AX,c ; load from location c into AX • OUT AX ; print out sum to the user Equivalent pascal code readln(a); readln(b); c := a + b; writeln(c); CSCI 150: Introduction to Computer Science - Session 23

  23. More Assembly Language Samples • Look at the Pascal programs first and then the generated assembly language programs • Simplest program: ONE.PAS • Let’s look at the very simple example: NUMBER.PAS • To show looping: WHILE.PAS • Most complicated: FACT.PAS - implements factorial using a loop - let’s try with input of 4 ! Run at faster speed? Note: COMP1 is Very Fragile Program - might die at any time! CSCI 150: Introduction to Computer Science - Session 23

  24. Observations about Generated Assembly Language Code • Use of ‘generated’ constants: #C0 #C1 … show up whenever there is some kind of constant number in your program - • e.g. X := 5 or while x < (n+1 ) • Temporary variables with names _E0, _E1, etc; used to store partial results in memory locations. Used when doing things like • 2*(X+1) uses a temp for X+1 as well as a temp for 2*(X+1) • New ‘instruction’ NO-OP = no-operation - just a place where we can add a label for jumps! • Notice any redundancy in the code sequences??? CSCI 150: Introduction to Computer Science - Session 23

  25. But how did we get here? • We have seen HOW the computer can execute the assembly language program - like we could use CircuitMaker to run a circuit • But where did the assembly language statements come from?(Where did circuit come from?) • Or more specifically – • How Do We Generate the Assembly Language for a given Pascal Program? • This is called Language TRANSLATION- The Main Topic of Chapter 9 CSCI 150: Introduction to Computer Science - Session 23

  26. Language Translation - Chapter 9 • Enabling the Computer to Understand Pascal • Syntactic Production Rules • Attaching Semantics to the Rules • The Semantics of Pascal • The Translation of Looping Programs (optional?) • Programming Languages CSCI 150: Introduction to Computer Science - Session 23

  27. Enabling the Computer to Understand Pascal • The computer hardware is unable to understand the Pascal language • But it can understand machine language or even assembly language • So how to get from Pascal to (P88) assembly? • E.g. how to do: Z := X + Y; copy AX,Xadd AX,Ycopy CN1,AXcopy AX,CN1copy Z,AX Pascal Source Code: Hardware cannot execute Assembly Language: Hardware can execute CSCI 150: Introduction to Computer Science - Session 23

  28. Syntactic Production Rules • Recall from Chapter 1: ’Arrow Notation’ : Rules to ‘describe the Pascal statements’ • Example:<statement> ==> <identifier > := <expression >( a statement may be: identifier := expression) • We could use these types of rules to produce / write (all) valid Pascal programs • Every computer language has such a set of syntactic production rules (with varying levels of complexity) also known as the grammar of the language CSCI 150: Introduction to Computer Science - Session 23

  29. Attaching Semantics to the Rules • But how do we go from writing valid programs to programs which can be executing programs? • Two step process: • Derive the appropriate set of production rules for a given program • As you did for homework assignment • Attach ‘meaning’ (aka semantics) to each rule as it is detected • meaning takes the form of equivalent assembly language code • Example: • the assignment production rule <ident> := <expr>;has the ‘meaning’COPY AX,M(expr) COPY M(ident),AX • Apply this process to the whole program - this is called compiling - generating assembly code from source code Where M(expr) means the memory location allocated for the expression and M(ident) is the memory location allocated to the variable identifier CSCI 150: Introduction to Computer Science - Session 23

  30. The Semantics of Pascal • Thus to EACH syntactic rule we must assign the semantics or meaning of that rule • See pages in the text for the semantics (code fragment) for other production rules • See page 287 for semantics of add and subtract rules! • See next slide for semantics of the addition expression Key concept in code generation of a compiler CSCI 150: Introduction to Computer Science - Session 23

  31. Semantics of the Pascal Add Expression If there is a match with this rule R4: <e>  ( <e1> + <e2> ) : M(<e>) = createname (for temp variable) code (<e> ) = code ( <e1> ) code ( <e2> ) COPY AX, M(<e1>) ADD AX, M(<e2>) COPY M(<e>), AX Do these steps in the compiler Assembly code generated CSCI 150: Introduction to Computer Science - Session 23

  32. Semantics of the entire program • Just apply these rules repetitively (and recursively) to all the productions as they unfold and you will end up with a set of assembly code which implements the intent of the original pascal code! • Can show more of this dynamically using COMP2 - a Visual Compiler CSCI 150: Introduction to Computer Science - Session 23

  33. COMP2 - Visual Compiler Pascal Source Generated Assembly Code Data Needed By The Program Production Rules with Assembly Code Consider ONE.PAS source file again but this time let’s watch the compilation process! Then NUMBER.PAS CSCI 150: Introduction to Computer Science - Session 23

  34. The Translation of Looping Programs (?) • Skip this - much too complicated CSCI 150: Introduction to Computer Science - Session 23

  35. Programming Languages • Summary of popular computer languages • Pascal - of course - developed primarily as a teaching language - variants: Turbo Pascal, Object Pascal, Free Pascal ... • Basic - teaching language - simple to build/run … a strong descendant: Microsoft’s Visual Basic language • COBOL - COmmercial Business Oriented Language • Fortran - FORmula TRANslation language - numerical calculations - science/engineering • Lisp - “Lots of Insipid Stupid Parentheses”, highly recursive, used for Artificial Intelligence projects • Forth - small, fast, stack-based language for embedded (built in to hardware) applications • C - standardized, highly portable language of 70’s-90’s • C++/Java - object oriented languages, derived from C • C# - Microsoft’s version of Java (!) • JavaScript – subset of Java used within browser-based programs CSCI 150: Introduction to Computer Science - Session 23

  36. Summary of Session Topics • Computer Architecture • hardware components • instruction set • Assembly Language • how to program the instruction’s instruction set • P88 - a simple, sample computer architecture • COMP1 - P88 simulator • PASCAL --> Assembly Language - Translation • How does it happen? • Production rules and semantics • COMP2 : a Visual Compiler Pascal to P88 Pascal Assembly Language P88 CSCI 150: Introduction to Computer Science - Session 23

  37. Next Session • Tuesday, April 22nd • A LAB – in Haberlin 408 • HTML and Web Pages!!! • Using PFE and The Internet Explorer Browser (IE) CSCI 150: Introduction to Computer Science - Session 23

More Related