1 / 24

From Algorithms to Architecture

A lightning introduction to computer architecture, covering topics from algorithms to architecture and implementing algorithms on a computer.

donaldsons
Download Presentation

From Algorithms to Architecture

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. From Algorithmsto Architecture ...a lightning introduction to computer architecture David Davenport Computer Eng. Dept., Bilkent UniversityAnkara - Turkey. email: david@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) taxRate (real 0-27.5) Might also specify whether information can be changed or noti.e. is constant/variable 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. memory input output Arithmetic & Logic Unit ALU 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 memory input output ALU 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. memory 5 2 output input 6 3 8 1 1 2 3 4 5 6 7 8 9 10 11 12 13 7 4 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 12 ALU 0 0 0 0 1 0 0 0 0 0 0 1 0 13 9 0 0 0 1 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 10 11 How it works… • Switches control data flow into and out of memory. • Sequence of switch settings determines function

  11. memory input output ALU 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 machine’s function can be changed quickly & easily. Control Limitation: may be out of program memory, yet have free data memory or vice versa!

  12. Control PC memory input output ALU 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

  13. Spaghetti Code? • “go to” programming… Default is next instruction • Read first number • If first number > 10 then go to 4 • go to 1 • Read second number • If second number <= first number goto 8 • Print “Well done” • go to 10 • Print “sorry, no good!” • go to 4 • Print “finished.”

  14. Control PC memory input output ALU 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.99999%of all computers still work like this!

  15. High-speed, volatile, expensive, so limited. Non-volatile, cheap, so plentiful, but slow! SemiconductorRAM, ROM Optical & Magnetic Disks, tapes & CDROMs Practical Considerations • Memory crucial to system speed! • Memory technology Speeddifferential>10,000x

  16. Control PC Primary memory input output ALU Memory Hierarchy • Result of today’s technological limitations only! Boot ROM Secondary memory(disks) Primary memory also called RAM – Random Access Memory

  17. From problem to execution • From requirements to algorithm • From algorithm to program (something understandable to machine) • Ultimately need machine code (1’s & 0’s 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!

  18. Language Hierarchy (1) • Machine code • Patterns of 1’s & 0’s ~ machine instruction • Usually restricted, e.g. no real numbers • Difficult & error-prone writing by hand! 1001100011000011 01000000 01000110 11111000 10000110 00000011 11111100 : Note: machine dependent, same operation may require different pattern of 1’s & 0’s on different machines. Computer designer/manufacturer defines machine code.

  19. 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 @R0 : Like machine code, assembly language is machine dependent and low-level

  20. 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

  21. 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…

  22. 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…

  23. // Program MyProg // David, Oct 2002 import java.io.*; Import cs1.JRobo; public class MyProg { public static void mai System.out.println( JRobo robby = new J robby.f(100); robby.rect( 150, 50); } } Javacompiler(javac) bytecode(stored in file) 11000111000100010000011110011100010101010001… Source code(stored in file) Javainterpreter(java) machine code (generated & executed,never stored) 11100101001000100… 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)

  24. <html><body> <applet class=“MyApplet.class”> </applet> </body> WebBrowser – Netscapehttp://somewhere.com/mypage.html // Program MyApplet // David, Oct 2002 import java.io.*; Import cs1.JRobo; public class MyApplet extends Applet { public void paint( JRobo robby = new J robby.f(100); robby.rect( 150, 50) } } My WebPage Look at this applet… html webpagecontaining applet(stored in file) INTERNET Javacompiler(javac) Welcome toMyApplet bytecode(stored in file) 11000111000100010000011110011100010101010001… Source code(stored in file) Javainterpreter(java) 11100101001000100… Programs across Internet • Java Applets – run anywhere safely! Mypage.html MyApplet.java MyApplet.class JVM in webbrowser creates machine code for client

More Related