Lesson 1 Computers and Programming Languages Characteristics of

  • Slides: 35
Download presentation
Lesson 1 Computers and Programming Languages Characteristics of computers Ø Mechanization of arithmetic Ø

Lesson 1 Computers and Programming Languages Characteristics of computers Ø Mechanization of arithmetic Ø Programmable *** History of computing machines Ø 1642, Pascaline (Pascal adder) Ø Blaise Pascal, a French mathematician Ø Mechanical Ø + and – Ø Shoe-box size 1

Ø 1670, Leibniz’s calculator Ø von Leibniz, a German mathematician Ø Mechanical Ø +,

Ø 1670, Leibniz’s calculator Ø von Leibniz, a German mathematician Ø Mechanical Ø +, –, *, / 2

Ø 1800 s, Babbage Analytical Engine Ø C. Babbage, English mathematician Ø supports arithmetic

Ø 1800 s, Babbage Analytical Engine Ø C. Babbage, English mathematician Ø supports arithmetic operations with storage for data Ø Mechanical Ø Programmable, controlled by punch cards Ø Ada Augusta, assistant, 1 st programmer 3

Ø 1946, ENIAC Ø Eckert & Mauchly, Univ. Pennsylvania, USA Ø Electronic, 19, 000

Ø 1946, ENIAC Ø Eckert & Mauchly, Univ. Pennsylvania, USA Ø Electronic, 19, 000 vacuum tubes Ø 1, 500 relays Ø 60, 000 pounds, 16, 200 ft 3 Ø program via re-wiring Ø 5000 arithmetic operations / sec. 4

Ø Late 1940 s Øvon Neumann, Princeton, USA Øprograms stored as data during execution

Ø Late 1940 s Øvon Neumann, Princeton, USA Øprograms stored as data during execution Ø 1958, IBM 7090, transistors Ø 1964 IBM System/360, integrated circuits 5

6

6

Ø 1980 s, most computers, VLSI (Very Large Scale Integrated circuits) Ø 1999, PC

Ø 1980 s, most computers, VLSI (Very Large Scale Integrated circuits) Ø 1999, PC Ø Pentium II processor Ø 333 MHz; 7. 5 M transistors Ø Main memory: 64 Mbyte; Ø Hard disk: 4 Gbyte; Ø Price: HK$10, 000 Ø 2004, PC Ø Pentium 4 processor Ø 3 GHz; 125 M transistors Ø Main memory: 512 Mbyte Ø Hard disk: 80 Gbyte; Ø Price: HK$5, 000 7

Moore’s Law The number of transistors in a chip is doubled every couple of

Moore’s Law The number of transistors in a chip is doubled every couple of years (Exponential growth) 8

Basic components of a computer Secondary Storage Main Memory Input Unit Control Arithmetic &

Basic components of a computer Secondary Storage Main Memory Input Unit Control Arithmetic & Unit Logic Unit Output Unit Central Processing Unit (CPU) Network Interface Internet 9

Ø Central Processing Unit (CPU) ØArithmetic and logic unit A Pentium 4 chip Ø+,

Ø Central Processing Unit (CPU) ØArithmetic and logic unit A Pentium 4 chip Ø+, –, *, /, … Øcomparison: >, <, ==, >=, . . . Ølogical AND, OR, … ØControl unit ØInstruction execution cycle 1. 2. 3. 4. 5. 6. fetch next instruction in RAM, decode the instruction, fetch the data from RAM, if needed, carry out the operation, store the result in RAM, if needed, repeat the entire cycle from Step 1. 10

Ø Main Memory (Primary Memory) Ø individually accessible storage cells with addresses Ø Each

Ø Main Memory (Primary Memory) Ø individually accessible storage cells with addresses Ø Each cell stores 1 byte (8 bits) Ø random access memory (RAM) Ø Read & write 000001 Ø Electronic, silicon chips 00010 00011 Ø fast 00100 Ø volatile (Data are lost when power is off. ) 11

Ø Secondary storage, e. g. , hard disk A disk surface contains magnetic tracks

Ø Secondary storage, e. g. , hard disk A disk surface contains magnetic tracks organized in concentric circles. A track is divided into sectors. A block of data (smallest unit, e. g. , 512 bytes) is stored in a sector. Tracks Sectors Gaps 12

ØDirect access The arm first moves to the targeted track. Then the read/write head

ØDirect access The arm first moves to the targeted track. Then the read/write head accesses the data when the targeted segment revolves underneath it. ØStorage: magnetic ØMovement: mechanical ØHigher capacity than RAM ØSlower than RAM ØCheaper than RAM ØNon-volatile (Data are retained even when power is off. ) ØTwo other common access mechanisms are: ØSequential access (tapes) ØRandom access (RAM) 13

Ø Input Units ØKeyboards ØMouse ØJoy sticks Ø Output Units ØMonitors ØPrinters ØSpeakers A

Ø Input Units ØKeyboards ØMouse ØJoy sticks Ø Output Units ØMonitors ØPrinters ØSpeakers A touch monitor supports both input and output 14

Terminology Ø Data: the physical form of information (singular: datum) ØA character (represented by

Terminology Ø Data: the physical form of information (singular: datum) ØA character (represented by 8 binary bits, ‘A’ is 01000001) ØA name (represented as a sequence of characters (a string) ) ØThe age of a person (represented as a 32 -bit integer) Ø File: Data stored on a disk, eg, ØA text file (containing only characters) ØA file that stores a sequences of student records. A record contains Name: Chan Tai Man UID: 20020323888 Tel: 29592193. . . ØA Power. Point file 15

Ø A bit is a binary digit. Its value is either 0 or 1.

Ø A bit is a binary digit. Its value is either 0 or 1. Ø A byte consists of 8 bits Ø An algorithm is a sequence of precise instructions that leads to a solution (Similar to a recipe. ) A recipe is a set of instructions for a person to carry out, eg, A recipe for preparing a fish dish: 1. 2. 3. 4. Clean a 1 -pound fish. Cut the fish into two halves. Fry the fillets in boiling oil for 6 minutes. Add soy sauce and green onions right before serving. Ø A computer program is a set of precise instructions for a computer to execute. 16

//A C++ program that converts temperature #include <iostream> using namespace std; int main() {

//A C++ program that converts temperature #include <iostream> using namespace std; int main() { int f, c; //Declarations cout << "Enter the temperature in Fahrenheit: "; cin >> f; c = (f - 32) * 5 / 9; cout << "The temperature in Centigrade is: " << c << "n"; system("PAUSE"); return 0; } Run the program 17

Hardware: physical machinery of a computer system Øa Notebook PC Øa network card Øa

Hardware: physical machinery of a computer system Øa Notebook PC Øa network card Øa monitor Øa printer Software: a collection of programs ØMS Word, a software package for preparing documents ØWindow 2000, an operating system on PC ØA Java compiler for translation ØNetscape for surfing the Internet 18

Software Life Cycle 1. 2. 3. 4. 5. 6. Analysis and specification of the

Software Life Cycle 1. 2. 3. 4. 5. 6. Analysis and specification of the task Design of the software Implementation Testing Maintenance Obsolescence 19

Problem-solving phase Start Implementation phase Problem definition Algorithm design Translating to C++ Desktop testing

Problem-solving phase Start Implementation phase Problem definition Algorithm design Translating to C++ Desktop testing Testing We will focus on the impl. phase in this course. Working program 20

Programming Languages Ø Machine Languages Ø Data are represented as a sequence of bits,

Programming Languages Ø Machine Languages Ø Data are represented as a sequence of bits, eg, 00000101 is 5. Ø Instructions are represented as a sequence of bits too, e. g. , 000101 00001100 Operation Data sources/destination Add the numbers in Register 1 and the memory cell at location 00001100; store the sum in Register 1. Ø A register is a high-speed memory cell in cpu. A cpu may contains many registers. Ø A program on a disk must be first loaded in RAM before the execution starts Ø Machine dependent (Different computers have different machine languages. ) 21

Ø Assembly Languages Ø Instructions are represented by symbolic names that make sense to

Ø Assembly Languages Ø Instructions are represented by symbolic names that make sense to human beings, e. g. , Add the no. in Register 1 to the no. ADD R 1, count in the location called count; Store STORE R 1, SUM the sum in the Register. [assembly lang. Program] [mach. Lang. Program] Assembler (software) Ø One assembly instruction is translated into one machine instruction Ø Assembly language is machine dependent 22

Ø High-level Languages Ø Instructions appeared in a form similar to natural languages or

Ø High-level Languages Ø Instructions appeared in a form similar to natural languages or mathematical formulas. E. g. , n = 3; Put 3 in the memory location sum = a + b + c; if (n != 0) average = sum / n; called n. Ø A compiler translates source code into object code [Source program] in high-level lang. Compiler [object program] in machine lang. Executed by a computer ØOne statement may be translated into hundreds of machine instructions ØExamples: Fortran, Pascal, C, C++ 23

Ø Linking An object program may be put together with other build-in programs in

Ø Linking An object program may be put together with other build-in programs in libraries before the execution. A linker is a program that carries out the linking operation. Ø Loading An object/pseudocode program must be first loaded in RAM before the execution. Ø Portable (Machine independent) A program written in a high level language can be compiled and executed in various computers. 24

Ø Syntax Ø The grammar that specifies the correct form of a language. Ø

Ø Syntax Ø The grammar that specifies the correct form of a language. Ø A syntax rule for <assignment statement> <assign stat> <id> = <expression> ; E. g. , A = B+C; Ø A syntax diagram for <compound statement> { E. g. , { <statement> A =B+1; If (C > 0) D = -1; } } 25

Ø Syntax rules that specify balanced parentheses 1. E () 2. E (E) 3.

Ø Syntax rules that specify balanced parentheses 1. E () 2. E (E) 3. E EE Ø All balanced paren. can be generated using the rules , eg, E EE (Rule 3) (E)E (Rule 2) (())E (Rule 1) (())(E) (Rule ? ) (())(EE) (())(()()) Ø There is no way to derive an unbalanced parentheses from the rules , eg, (()(() 26

Ø Semantics Rules which give the meanings of statements. E. g. , <id> =

Ø Semantics Rules which give the meanings of statements. E. g. , <id> = <expression> ; means: evaluate the <expression>; store the result in the memory location represented by <id>. E. g. , apply the rule to evaluate A = B + C ; Ø Examples of high-level languages Ø FORmula TRANslation (FORTRAN) Ø John Backus Ø Numerical Analysis Ø The Oldest Ø COmmon Business-Oriented Language (COBOL) Ø For commercial applications Ø Once promoted by US government 27

Ø ALGOrithmic Language (ALGOL) ØFor coding algorithms ØWell designed ØPredecessor of PASCAL Ø Beginner’s

Ø ALGOrithmic Language (ALGOL) ØFor coding algorithms ØWell designed ØPredecessor of PASCAL Ø Beginner’s All-Purpose Symbolic Instruction Code (BASIC) Ø Poorly designed Ø APL (A Programming Language) Ø PL/I (Programming Language I), once promoted by IBM Ø LISP, PROLOG, ADA (promoted by US Defense Dept) Ø B, C Ø C++ 28

Ø B was developed by Ken Thompson, the originator of UNIX Ø C was

Ø B was developed by Ken Thompson, the originator of UNIX Ø C was developed by Dennis Ritchie of AT&T Bell Lab in 1972 Ø A high-level language with low-level features Ø Easy-to-write, but hard-to-read Ø Not safe (No automatic checks) Ø Not Object-oriented Ø C++ was developed by Bjarne Stroustrup of Bell Lab in early 1980 s Ø Object-oriented Ø Intricate, in addition to other shortcomings of C 29

ØTuring Award Ø Offered by America Computing Machinery (ACM) Ø In memory of Alan

ØTuring Award Ø Offered by America Computing Machinery (ACM) Ø In memory of Alan Turing Ø UK Applied Mathematician Ø Theorist on computer models Ø Study the power of computer Can we have a program that determines whether the execution of a program will halt or not? Ø http: //www. turing. org. uk/turing/ Ø Highest honor in computer science Ø Offered annually 30

Turing Award Laureates 1966 A. J. Perlis 1976 Dana S. Scott 1967 Maurice V.

Turing Award Laureates 1966 A. J. Perlis 1976 Dana S. Scott 1967 Maurice V. Wilkes 1977 John Backus FORTRAN 1968 Richard Hamming 1978 Robert W. Floyd 1969 Marvin Minsky 1979 Kenneth E. Iverson APL 1970 J. H. Wilkinson 1980 C. Antony R. Hoare Prog. Lang. 1971 John Mc. Carthy 1981 Edgar F. Codd 1972 E. W. Dijkstra ALGOL 1982 Stephen A. Cook 1973 Charles W. Bachman 1983 Ken Thompson UNIX, C 1974 Donald E. Knuth 1983 Dennis M. Ritchie C 1975 Allen Newell 1984 Niklaus Wirth PASCAL 1975 Herbert A. Simon 1985 Richard M. Karp 1976 Michael O. Rabin 1986 John Hopcroft 31

1986 Robert Tarjan 1997 Douglas Engelbart 1987 John Cocke 1998 James Gray 1988 Ivan

1986 Robert Tarjan 1997 Douglas Engelbart 1987 John Cocke 1998 James Gray 1988 Ivan Sutherland 1999 Frederick P. Brooks, Jr. 1989 William (Velvel) Kahan 2000 Andrew Chi-Chih Yao 1990 Fernando J. Corbato' 1991 Robin Milner 1992 Butler W. Lampson 姚期智教授 Theory of Computation 1993 Juris Hartmanis 1993 Richard E. Stearns 1994 Edward Feigenbaum 1994 Raj Reddy 2001 Johan Dahl and Kristen Nygaard OOP 1995 Manuel Blum 2002 R. L. Rivest, A. Shamir & L. M. Adleman 1996 Amir Pnueli 2003 Alan Kay OOP 32

Truths that might hurt (18 th June 1975) Edsger W. Dijkstra 1930 -2002 z

Truths that might hurt (18 th June 1975) Edsger W. Dijkstra 1930 -2002 z It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. z FORTRAN --"the infantile disorder"--, by now nearly 20 years old, is hopelessly inadequate for whatever computer application you have in mind today: it is now too clumsy, too risky, and too expensive to use. 33

Truths that might hurt z The use of COBOL cripples the mind; its teaching

Truths that might hurt z The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence. z Besides a mathematical inclination, an exceptionally good mastery of one's native tongue is the most vital asset of a competent programmer. z Simplicity is prerequisite for reliability. 34

Reading Assignment Ø Chapter 1 of the Text, P. 1 -39 35

Reading Assignment Ø Chapter 1 of the Text, P. 1 -39 35