From Algorithms to Architecture - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

From Algorithms to Architecture

Description:

This presentation is designed to be used in class as part ... Credited to John von Neumann, circa 1946. Today. 99.99999% of all computers still work like this! ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 25
Provided by: davidda3
Category:

less

Transcript and Presenter's Notes

Title: From Algorithms to Architecture


1
From Algorithmsto Architecture
...a lightning introduction to computer
architecture
  • David Davenport
  • Computer Eng. Dept.,
  • Bilkent UniversityAnkara - Turkey.
  • email david_at_bilkent.edu.tr

2
IMPORTANT
  • Students
  • This presentation is designed to be used in class
    as part of a guided discovery sequence. It is not
    self-explanatory! Please use it only for revision
    purposes after having taken the class. Simply
    flicking through the slides will teach you
    nothing. You must be actively thinking, doing and
    questioning to learn!
  • Instructors
  • You are free to use this presentation in your
    classes and to make any modifications to it that
    you wish. All I ask is an email saying where and
    when it is/was used. I would also appreciate any
    suggestions you may have for improving it.

thank you, David.
3
Implementing Algorithms
  • Now have a methodology for going from problem to
    program
  • Next develop a mental model of a device that
    might actually execute our algorithm, i.e. a
    computer!

4
Memory Mental Model
  • Information
  • anything a number, letter, word, a report, book,
    picture, music, animation, a collection of
    books
  • written/drawn on a paper
  • cannot be changed!
  • Store in Box
  • can hold only a single paper
  • can examine/copy paper at will
  • replacing paper destroys old
  • always a paper in box!

Some infoon a piece of paper!
5
Computer Memory
  • Set of memory locations
  • To identify easily, number or name them
  • To minimise bugs, restrict type of content

salary (positive real)
username (string)
address (string)
radius (positive integer)
holidaypic (image)
age (integer 0-150)
Might also specify whether information can be
changed or noti.e. is constant/variable
taxRate (real 0-27.5)
speedOfLight (integer 300)
6
Area-Circumference Problem
  • To find area circumference of circle
  • Print welcome message
  • Ask for get radius from user
  • Compute area as pi.radius.radius
  • Compute circumference as 2.pi.radius
  • Report area, circumference radius

Information flowing from one step to another must
be stored so needs a place in memory
7
Algorithm
  • Envisage area/circumference algorithmin terms of
    computer memory model

radius (positive integer)
area (positive real)
circumference (positive real)
pi (constant3.142)
2 (constant2.0)
8
Data flow
  • Only three sorts of instructions
  • input - from external world to memory
  • output - from memory to world
  • assignment - from memory to memory

9
Control flow (1)
  • Control mechanism implements algorithm
  • sets up the data paths in appropriate sequence

First computing devices had control mechanisms
that were hardwired (fixed) or at best
pluggable e.g ENIAC
Changing the function of the machine required
literally changing its wiring!
10
How it works
  • Switches control data flow into and out of
    memory.
  • Sequence of switch settings determines function

11
How it works
  • Switches control data flow into and out of
    memory.
  • Sequence of switch settings determines function

output
input
ALU
12
Control flow (2)
  • Recognising
  • only three forms of control sequence
    required(sequence, decision repetition)
  • instructions can be encoded in memory like data
  • allows general control mechanism to be implemented

Programmemory
Instructions hence the machines function can
be changed quickly easily.
Control
Limitation may be out of program memory, yet
have free data memory or vice versa!
13
Control flow (3)
  • Finally
  • realise that program data can share same memory

Instructions stored in sequentially numbered
locations in memory. Current position in program
held in program counter. Control fetches current
instruction, decodes executes it (by setting
data paths), increments PC, then fetches next
instruction, and so on.
Fetch Execute cycle
Memory now holds both program data
14
Spaghetti Code?
  • go to programming

Default is next instruction
  • Read first number
  • If first number gt 10 then go to 4
  • go to 1
  • Read second number
  • If second number lt first number goto 8
  • Print Well done
  • go to 10
  • Print sorry, no good!
  • go to 4
  • Print finished.

15
Von Neumann Architecture
  • Stored-program computer architecture
  • Credited to John von Neumann, circa 1946

CPU Central Processing Unit (note ALU may be
considered part of it too.)
Today99.99999of all computers still work like
this!
16
Practical Considerations
  • Memory crucial to system speed!
  • Memory technology

Speeddifferentialgt10,000x
17
Memory Hierarchy
  • Result of todays technological limitations only!

Boot ROM
Secondary memory(disks)
Primary memory also called RAM Random Access
Memory
18
From problem to execution
  • From requirements to algorithm
  • From algorithm to program (something
    understandable to machine)
  • Ultimately need machine code (1s 0s
    representing voltage patterns)
  • but how do we get it?
  • Directly write machine code
  • Write assembly translate
  • Write high-level translate

Translation is a symbol manipulation task!
19
Language Hierarchy (1)
  • Machine code
  • Patterns of 1s 0s machine instruction
  • Usually restricted, e.g. no real numbers
  • Difficult error-prone writing by hand!

1001100011000011 01000000 01000110 11111000 10000
110 00000011 11111100
Note machine dependent, same operation may
require different pattern of 1s 0s on
different machines. Computer designer/manufacturer
defines machine code.
20
Language Hierarchy (2)
  • Assembly language
  • Each machine instruction has mnemonic
  • Easier to remember understandso slightly less
    error-prone, but still difficult to do even
    simple things!
  • One-to-one mappingso translation to machine code
    is trivial
  • Use program to do translation (assembler)

MOV 5, R1 ADD R1, R2 STR _at_R0
Like machine code, assembly language is machine
dependent and low-level
21
Language Hierarchy (3)
  • High-level language
  • Much more natural, e.g. has real numbers!
  • Much easier to understand write
  • Language standards, so machine independent
  • Translation to machine code is complexuse
    program to do translation!

This program must itself be able to be executed
on the machine being used!
input A Z A 3 1 print( Z . Z)
  • Two approaches
  • Interpret
  • Compile

22
Interpreters
  • Translate immediately execute each instruction
    in turn

10 rem Sum two numbers20 input enter first
number, a30 input enter second number,
b 50 output sum is . s
Source code(stored in file)
40 s a b
interpreter
machine code (generated executed,never stored)
11100101001000100
23
Compilers
  • Translate all instructions to machine code,save
    execute as needed

10 rem Sum two numbers20 input enter first
number, a30 input enter second number, b40
s a b50 output sum is . s
Source code(stored in file)
compiler
machine code (generated once stored in file)
Stored machine code executed by OS as many times
as required!
001100010101000010011100101001000100
24
Java compile interpret
  • Compile save to bytecode (machine independent)
  • Execute by interpreting bytecode

MyProg.java
MyProg.class
Also known as the Java Virtual Machine (JVM)
25
Programs across Internet
  • Java Applets run anywhere safely!

Mypage.html
MyApplet.java
MyApplet.class
JVM in webbrowser creates machine code for client
Write a Comment
User Comments (0)
About PowerShow.com