Introduction to Computer Science CSCI 150 Section 002 Session 23 PowerPoint PPT Presentation

presentation player overlay
1 / 37
About This Presentation
Transcript and Presenter's Notes

Title: Introduction to Computer Science CSCI 150 Section 002 Session 23


1
Introduction to Computer ScienceCSCI 150
Section 002Session 23
  • Dr. Richard J. Bonneau
  • IONA Technologies
  • Rich.Bonneau_at_iona.com

2
Todays Outline
  • Todays notices
  • Tonights 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
Todays Notices
  • Office Swords 339
  • Extension 2284
  • Office hours Tu-Th 4-630 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
  • Todays 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 230 in
    Haberlin Lab 408 change of room!!

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 Makers library
  • input devices, animation, cars and rockets

5
Outline of Chapters 8 9 - Machine Architecture
and Language Translation
  • Machine Architecture - Chapter 8
  • Lets 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
Machine Architecture - Chapter 8
  • Lets Build A Computer!!
  • A Sample Architecture The P88 Machine
  • Programming the P88 Machine

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 CPUs - a parallel architecture??

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
  • ltSee architecture diagram on p. 260 and next
    slidegt
  • 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
Computer Organization - CPU
Address
Instruction in Memory
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
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 !!
12
P88 Simulator(s)
  • Programs COMP1 and COMP2 - available on the
    course web site athttp//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
P88 (COMP1) Program Interface
Pascal Source
Assembly Language Code In Memory
Data in Memory
CPU Registers
CPU Execution state
14
First simulator run!
  • Lets 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
Programming the P88 Machine
  • Lets 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
Copy Instructions
  • Data flows between memory and CPU through the
    COPY instructions
  • Two variantsCOPY AX,ltmemory addressgt AX
    lt--(memory) means load FROM memory into AX
    register COPY ltmemory addressgt,AX AX --gt
    (memory) means store AX contents to memory
    location
  • In both cases, COPY ltdestgt,ltsourcegt data moves
    from source to destination

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,ltmemorygt AX AX (memory value)SUB
    AX,ltmemorygt AX AX - (memory value)MUL
    AX,ltmemorygt AX AX (memory value)DIV
    AX,ltmemorygt AX AX / (memory value)

DIV is the same as Pascal Integer Divide
operation integer result only
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,ltmemorygt If AXlt(memory) then CF
    B
  • else CF NB

CF Register Value B Memory is Bigger than
AX NB Memory is NOT Bigger
19
Jump Instructions
  • Three instructions in this class First is
    unconditional, other two are conditional
  • First Unconditional Jump InstructionJMP ltlabelgt
    Load addr of ltlabelgt into IP reg(Note label is
    attached to another line of code in the program)
  • Next Conditional Jump InstructionsJB ltlabelgt If
    CF B then ltlabelgt -gt IPJNB ltlabelgt If CF
    NB then ltlabelgt -gt IP

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 users display

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)

22
Simple assembly language code
  • Simple assembly language sequence Input, Add two
    numbers, output to user

Equivalent pascal code readln(a) readln(b)
c a b writeln(c)
  • 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

23
More Assembly Language Samples
  • Look at the Pascal programs first and then the
    generated assembly language programs
  • Simplest program ONE.PAS
  • Lets look at the very simple example
    NUMBER.PAS
  • To show looping WHILE.PAS
  • Most complicated FACT.PAS - implements
    factorial using a loop - lets try with input of
    4 ! Run at faster speed?

Note COMP1 is Very Fragile Program - might die
at any time!
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 lt (n1 )
  • Temporary variables with names _E0, _E1, etc
    used to store partial results in memory
    locations. Used when doing things like
  • 2(X1) uses a temp for X1 as well as a temp
    for 2(X1)
  • 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
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
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
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
28
Syntactic Production Rules
  • Recall from Chapter 1 Arrow Notation Rules
    to describe the Pascal statements
  • Exampleltstatementgt gt ltidentifier gt
    ltexpression gt( 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
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 ltidentgt
    ltexprgthas 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
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
Semantics of the Pascal Add Expression
If there is a match with this rule
  • R4 ltegt ? ( lte1gt lte2gt )
  • M(ltegt) createname (for temp variable)
  • code (ltegt )
  • code ( lte1gt )
  • code ( lte2gt )
  • COPY AX, M(lte1gt)
  • ADD AX, M(lte2gt)
  • COPY M(ltegt), AX

Do these steps in the compiler
Assembly code generated
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

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 lets watch the compilation process! Then
NUMBER.PAS
34
The Translation of Looping Programs (?)
  • Skip this - much too complicated

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 Microsofts 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
    70s-90s
  • C/Java - object oriented languages, derived
    from C
  • C - Microsofts version of Java (!)
  • JavaScript subset of Java used within
    browser-based programs

36
Summary of Session Topics
  • Computer Architecture
  • hardware components
  • instruction set
  • Assembly Language
  • how to program the instructions instruction set
  • P88 - a simple, sample computer architecture
  • COMP1 - P88 simulator
  • PASCAL --gt Assembly Language - Translation
  • How does it happen?
  • Production rules and semantics
  • COMP2 a Visual Compiler Pascal to P88

Pascal Assembly Language P88
37
Next Session
  • Tuesday, April 22nd
  • A LAB in Haberlin 408
  • HTML and Web Pages!!!
  • Using PFE and The Internet Explorer Browser (IE)
Write a Comment
User Comments (0)
About PowerShow.com