CS 240 – Computer Science I
Total Page:16
File Type:pdf, Size:1020Kb
CS 240 – Computer Science I Acknowledgements: These slides were created by Dr. Travis Doom with information, graphics, materials, or aid kindly ppyrovided by Dr. Matt Rizki, Gaddis’s “Starting Out with Java” ( Addison Wesle y), Patt’s “Introduction to com puters” and McConnell’s “Code Complete”.. Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 1 An engineer’s introduction to abstraction and the digital computer Thdhe modern genera l purpose diildigital computer Abstraction/Encapsulation Design decomposition What is a computer? z What is computation? z There are many sorts of computing devices, they fall into two categories: – Analog: machines that produce an answer that measures some continuous physical property such as distance, light intensity, or voltage. Examples? – Digital: machines that perform computations by manipulating a fixed finite set of elements. Examples? – The difficulty with analog devices is that it is very hard to increase their accuracy. z Before modern digital computers, the most common digital machines were adding machines. – Adding machines perform exactly one sort of operation. z General purpose digital computers also perform one operation… – Mo dern compu ters accep t a se t o f inst ructi ons th at t ell it h ow t o d o any sort of comput ati on. z We now make a clear distinction between “calculators” and “computers” Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 3 How do we get the electrons to do the work? z We describe our problems in English or some other natural language. Computer problems are so lve d by e lec trons flow ing aroun d ins ide th e comput er. z It is necessary to transform our problem from a natural language to the voltages that influence the flow of electrons. z This transformation is really a sequence of systematic transformations , developed and improved over the last 50 years, which combine to give the computer the ability to carry out what may appear to be very complicated tasks. In reality, these tasks must decomposed into a number of simple and straight- forward subtasks. z Engineering design – Top down design – Decomposition into smaller problems (Divide and Conquer!) – Levels of Abstraction Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 4 The principle of design abstraction z General model for Engineering (Byrne, 1992) Alteration Reverse Con- re-think Con- Forward EiEngineeri ng ceteptual ceptual EiEngineeri ng Abstraction Refinement Requirementsre-specify Requirements Design re-design Design re-build Implementation Implementation Existing System Target System Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 5 Levels of abstraction in digital computation z Design Process The Problem CS 24x, 4xx Software level Computer Science Algorithm & Language CEG 320 Hardware level Computer Engineering ISA & Microarchitecture CEG 260/360 Logic level Computer/Elect. Engineering Circuits & Devices Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 6 The statement of the problem The Problem z We describe problems that we wish to solve wihith a computer in a “ natural ll language.” z Natural languages are fraught with a lot of things unacceptable for providing instructions Algorithm & Language to a computer. z The most important of these unacceptable attributes is ambiguity. To infer the meaning of a sentence, a listener i s of ten h el ped b y context ISA & Microarchitecture that the computer does not have. – “Mary had a little lamb and other nursery rhymes.” z A computer can not deal with any ambiguity, Circuits & Devices thus… Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 7 The algorithm The Problem z The first step in the sequence of transformations is to transform the natural language description of the problem to an algorithm. z An algorithm is a step-by-step procedure: – That transforms an input (possibly NULL) into Algorithm & Language some output (or output action) – That is guaranteed to terminate z Definiteness: Each step is precisely stated. z Effective computability: Each step must be ISA & Microarchitecture something the computer can perform z Finiteness: The procedure must terminate/repeat z For any computable problem, there are an infinite number of algorithms to solve it. Circuits & Devices – Which solution is best? Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 8 Exponential growth z 10^1 z 10^2 z 10^3 Number of students in the college of engineering z 10^4 Number of students enrolled at Wright State University z 10^6 Number of people in Dayton z 10^8 Number of people in Ohio z 10^10 Number of stars in the galaxy z 10^20 Total number of all stars in the universe z 10^80 Total number of particles in the universe z 10^100 << Number of possible solutions to traveling salesman (100) z Travelling salesman (100) is computable but it is NOT feasible. Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 9 The programming language The Problem z The next step is to transform the algorithm into a computer program z Programming languages are unambiguous “mechanical” languages Algorithm & Language z There are two kinds of programming languages: – High-level languages are machine independent. Th“fb”h(dli)hey are “far above” the (underlying) computer ISA & Microarchitecture – Low-level languages are machine dependent. They are tied to the computer on which the program will execute. There is generally only one such language per machine (referred to as its ASSEMBLY language). Circuits & Devices Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 10 How do we specify the program? z Contemporary languages – Java, C++, C , C# , Perl , Python, Ruby , and many more . z Languages of yore – Fortran, COBOL, and many more. z Specialty lang uages – VHDL, simulation languages, and many more. z There are over 1 ,000 “ stand ardi zed” programmi ng l anguages tod ay. z The only goal of these languages is to help humans implement their algorithms in the instructions available for a particular ISA – This is what we mean when we say “programming” Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 11 Universal computing devices z Turing’s Thesis: Computer scientists believe that ANYTHING that can be comppygppputed by a general purpose computer can be com pyygputed by any general purpose computer (provided that it has enough time and enough memory). z What does this imply? – All computers (from the least expensive to the most expensive) are capable of computing EXACTLY th e same thi ngs IF th ey are gi ven enough ti me and enough memory. – Some computers can do things faster, but none can do more than any other computer. – All comppyguters can do exactly the same things! z Thus, any given problem is either computable or it is not computable – Problems may be computable, but still not feasible (NPC) Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 12 The instruction set architecture (ISA) The Problem z The next step is to translate the program into the ins tructi on set of th e parti cul ar comput er th at will b e used to carry out the work of the program. z The Instruction Set Architecture (ISA) is the complete specification of the interface between Algorithm & Language programs that have been written and the underlying hardware that must carry out the work of those programs. – Examples: IA-32 (Intel, AMD, and others), PowerPC (Motorola) ISA & Microarchitecture z Programs are translated from high languages in to the ISA of the computer on which they will be run by a program called a compiler (specific to the ISA). – Some languages are interpreted as they execute. Circuits & Devices z Programs are translated from assembly to the ISA by an assembler. Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 13 Compilation vs. Interpretation z Different ways of translating high-level language Get W from the z Interpretation keyboard. – interpreter = program that executes program statements X = W + W – generally one line/command at a time Y = X + X – limited processing Z = Y + Y – easy to dbdebug, ma ke c hanges, v iew intermedi ate resul ts Print Z to screen . – languages: Java, BASIC, LISP, Perl, Matlab, C-shell How many arithmetic z Compilation operations when – translates statements into machine language interpreted? When z does not execute, but creates executable program compiled with – performs optimization over multiple statements optimization? – change requires recompilation z can be harder to debug, since executed code may be different – languages: C++, C, Fortran, Pascal, etc. Wright State University, College of Engineering CS 240 Dr. T. Doom, Computer Science & Engineering Computer Science I 14 The von Neumann Model - Illustration Memory MAR MDR Processing Unit Input ALU TEMP Output (keyboard) (monitor) Control Unit PC IR Memory: holds both data and instructions Processing Unit: carries