Presentation is loading. Please wait.

Presentation is loading. Please wait.

4/15/2003CSCI 150: Introduction to Computer Science - Session 231 Introduction to Computer Science CSCI 150 Section 002 Session 23 Dr. Richard J. Bonneau.

Similar presentations


Presentation on theme: "4/15/2003CSCI 150: Introduction to Computer Science - Session 231 Introduction to Computer Science CSCI 150 Section 002 Session 23 Dr. Richard J. Bonneau."— Presentation transcript:

1 4/15/2003CSCI 150: Introduction to Computer Science - Session 231 Introduction to Computer Science CSCI 150 Section 002 Session 23 Dr. Richard J. Bonneau IONA Technologies Rich.Bonneau@iona.com

2 4/15/2003CSCI 150: Introduction to Computer Science - Session 232 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

3 4/15/2003CSCI 150: Introduction to Computer Science - Session 233 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 24 th Final Exam – Saturday May 3 rd – 2:30 – in Haberlin Lab 408 – change of room!!

4 4/15/2003CSCI 150: Introduction to Computer Science - Session 234 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 …

5 4/15/2003CSCI 150: Introduction to Computer Science - Session 235 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!)

6 4/15/2003CSCI 150: Introduction to Computer Science - Session 236 Machine Architecture - Chapter 8 Let’s Build A Computer!! A Sample Architecture: The P88 Machine Programming the P88 Machine

7 4/15/2003CSCI 150: Introduction to Computer Science - Session 237 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??

8 4/15/2003CSCI 150: Introduction to Computer Science - Session 238 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 – 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!

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

10 4/15/2003CSCI 150: Introduction to Computer Science - Session 2310 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 }

11 4/15/2003CSCI 150: Introduction to Computer Science - Session 2311 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 !!

12 4/15/2003CSCI 150: Introduction to Computer Science - Session 2312 P88 Simulator(s) Programs COMP1 and COMP2 - available on the course web site at: http://mathcs.holycross.edu/~rbonneau/CourseFiles/P88 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!

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

14 4/15/2003CSCI 150: Introduction to Computer Science - Session 2314 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

15 4/15/2003CSCI 150: Introduction to Computer Science - Session 2315 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

16 4/15/2003CSCI 150: Introduction to Computer Science - Session 2316 Copy Instructions Data flows between memory and CPU through the COPY instructions Two variants: COPY AX, AX,AX AX --> (memory) means store AX contents to memory location In both cases, COPY, data moves from source to destination

17 4/15/2003CSCI 150: Introduction to Computer Science - Session 2317 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 Performed ADD AX, AX := AX + (memory value) SUB AX, AX := AX - (memory value) MUL AX, AX := AX * (memory value) DIV AX, AX := AX / (memory value) DIV is the same as Pascal Integer Divide operation – integer result only

18 4/15/2003CSCI 150: Introduction to Computer Science - Session 2318 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 Performed CMP AX, If AX<(memory) then CF = B else CF = NB CF Register Value: B = Memory is Bigger than AX NB = Memory is NOT Bigger

19 4/15/2003CSCI 150: Introduction to Computer Science - Session 2319 Jump Instructions Three instructions in this class: First is unconditional, other two are conditional First: Unconditional Jump Instruction JMP Load addr of into IP reg (Note label is attached to another line of code in the program) Next: Conditional Jump Instructions JB If CF = B then -> IP JNB If CF = NB then -> IP

20 4/15/2003CSCI 150: Introduction to Computer Science - Session 2320 Input/Output Instructions Two instructions - one for input and one for output Input instruction IN AXRead integer from user and store into AX Output instruction OUT AXPrint the contents of AX to user’s display

21 4/15/2003CSCI 150: Introduction to Computer Science - Session 2321 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)

22 4/15/2003CSCI 150: Introduction to Computer Science - Session 2322 Simple assembly language code –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); Simple assembly language sequence: Input, Add two numbers, output to user

23 4/15/2003CSCI 150: Introduction to Computer Science - Session 2323 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!

24 4/15/2003CSCI 150: Introduction to Computer Science - Session 2324 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???

25 4/15/2003CSCI 150: Introduction to Computer Science - Session 2325 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

26 4/15/2003CSCI 150: Introduction to Computer Science - Session 2326 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

27 4/15/2003CSCI 150: Introduction to Computer Science - Session 2327 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,X add AX,Y copyCN1,AX copy AX,CN1 copy Z,AX Pascal Source Code: Hardware cannot execute Assembly Language: Hardware can execute

28 4/15/2003CSCI 150: Introduction to Computer Science - Session 2328 Syntactic Production Rules Recall from Chapter 1: ’Arrow Notation’ : Rules to ‘describe the Pascal statements’ Example: ==> := ( 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

29 4/15/2003CSCI 150: Introduction to Computer Science - Session 2329 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 := ; 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

30 4/15/2003CSCI 150: Introduction to Computer Science - Session 2330 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

31 4/15/2003CSCI 150: Introduction to Computer Science - Session 2331 Semantics of the Pascal Add Expression R4:  ( + ) : M( ) = createname (for temp variable) code ( ) = code ( ) COPY AX, M( ) ADD AX, M( ) COPY M( ), AX If there is a match with this rule Do these steps in the compiler Assembly code generated

32 4/15/2003CSCI 150: Introduction to Computer Science - Session 2332 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

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

34 4/15/2003CSCI 150: Introduction to Computer Science - Session 2334 The Translation of Looping Programs (?) Skip this - much too complicated

35 4/15/2003CSCI 150: Introduction to Computer Science - Session 2335 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

36 4/15/2003CSCI 150: Introduction to Computer Science - Session 2336 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

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


Download ppt "4/15/2003CSCI 150: Introduction to Computer Science - Session 231 Introduction to Computer Science CSCI 150 Section 002 Session 23 Dr. Richard J. Bonneau."

Similar presentations


Ads by Google