Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture II Basic computer and programming concepts

Similar presentations


Presentation on theme: "Lecture II Basic computer and programming concepts"— Presentation transcript:

1 Lecture II Basic computer and programming concepts
Yi Lin Jan 09, 2007

2 What is computer? Computers are clever idiots Idiot: Do whatever it is ordered; Clever: But fast and never wrong. Who gives the orders? Programmers In what forms? Programs in certain syntaxes (i.e., in certain programming languages) 34253 * * = ? 11/19/2018 COMP208 Computers in Engr

3 Computer Windows XP, Linux, Microsoft Office, Internet Browser …
Software Pentium 4 CPU, AMD, 512 MB DDR memory, 19 inch LCD, Keyboard, … Hardward 11/19/2018 COMP208 Computers in Engr

4 Computer Hardware Von Neumann model …… FETCH and EXECUTE storage
Command n Command 2 …… Von Neumann model FETCH and EXECUTE Command 1 Command n storage Command 2 storage Command n …… storage Command n …… Command 2 Monitor results processor 11/19/2018 COMP208 Computers in Engr

5 Computer Hardware Keyboard Hard Disk Memory BUS Cache Register Monitor
Printer Register CPU 11/19/2018 COMP208 Computers in Engr

6 The 5 Classic Components
Computer CPU Memory Control Input Devices Registers Output Devices That is, any computer, no matter how primitive or advance, can be divided into five parts: 1. The input devices bring the data from the outside world into the computer. 2. These data are kept in the computer’s memory until ... 3. The datapath request and process them. 4. The operation of the datapath is controlled by the computer’s controller. All the work done by the computer will NOT do us any good unless we can get the data back to the outside world. 5. Getting the data back to the outside world is the job of the output devices. The most COMMON way to connect these 5 components together is to use a network of busses. 11/19/2018 COMP208 Computers in Engr 6

7 Input / Ouput Input Output Those are only the ones I came up with when I wrote this slide… 11/19/2018 COMP208 Computers in Engr

8 Computer Software (program)
A program is a set of step-by-step instructions that directs the computer to do the tasks you want it to do and produce the results you want. In what form? E.g., Windows XP, Red hat, Microsoft Office (Word, PowerPoint, Excel), Computer Virus … Showing a few example programs, BallGame, TypingGame, … 11/19/2018 COMP208 Computers in Engr

9 Different natural languages
Wie geht es Ihnen? How are you? And more …… Comment allez-vous? 你好吗? 11/19/2018 COMP208 Computers in Engr

10 Different programming languages
C++ C# C Assembly (Intel8086, Motorola68000) Machine language And more …… Fortran Java 11/19/2018 COMP208 Computers in Engr

11 Very high level language
Levels of language Natural language Easiness for human, i.e., more flexibility, easier to be implemented, maintained Very high level language (e.g., Java, C++, SQL) High level language (e.g., Fortran, C, Cobol) Assembly language (Intel: 8086, Motorola: 68000, Sun: Sparc) Machine Language (e.g., ) Speed 11/19/2018 COMP208 Computers in Engr

12 Choosing a language Manager choices a language for everyone in the group Suitable for your tasks Satellite communication (speed) Assembly Education Basic, Pascal Business  Cobol Web development Javascript, Java Scientific calculation Fortran Real programmer in general purpose C 11/19/2018 COMP208 Computers in Engr

13 Major programming language: Fortran
The First High-Level Language Developed by IBM and introduced in 1957 Primarily associated with engineering, mathematical, and scientific research tasks. Rich in math library 11/19/2018 COMP208 Computers in Engr

14 Major programming language: COBOL
The Language of Business Although Fortran in 1950s, no high level language for business.. The U.S. Department of Defense: CODASYL-COnference of DAta SYstem Languages. 1959 COBOL-COmmon Business Oriented Language. 1974, American National Standards Institute: ANSI-COBOL 1985, COBOL 85 COBOL is very good for processing large files and performing relatively simple business calculations, such as payroll or interest. English-like-far more than FORTRAN or BASIC 11/19/2018 COMP208 Computers in Engr

15 Major programming language: Basic
For Beginners and Others BASIC-Beginners' All-purpose Symbolic Instruction Code Developed at Dartmouth College by John Kemeny and Thomas Kurtz in 1965 and originally intended for use by students. For many years, BASIC was looked down on by "real programmers," who complained that it had too many limitations and was not suitable for complex tasks. Newer versions, such as Microsofts QuickBASIC, include substantial improvements. 11/19/2018 COMP208 Computers in Engr

16 Major programming language: C
A language invented by Dennis Ritchie at Bell Labs in 1972 Advantage: C very fast ≈ assembly language while still offering high-level language features. Disadvantage: Although C is simple and elegant, it is not simple to learn. C was originally designed to write systems software but is now considered a general-purpose language. The availability of C on personal computers has greatly enhanced the value of personal computers for budding software entrepreneurs. 11/19/2018 COMP208 Computers in Engr

17 Let’s start A simplest Fortran program
11/19/2018 COMP208 Computers in Engr

18 Hello World! Edit: PROGRaM hello IMPLIcIT NONE
WRITE(*,*) "Hello World!" END PROGRaM HelloWorld.f90 Edit: any text editor, e.g., SciTE, Notepad, Or IDE (Integrated Development Environment), e.g., Visual Fortran 11/19/2018 COMP208 Computers in Engr

19 Hello World (cont.) Edit (open a scite editor) compile
Fortran  Machine Language Scite menu: Tools->compile (Ctrl+F7) Link (not necessary for simple programs) Linking libraries used in the program Run Scite menu: Tools ->go (F5) Output: “Hello World!” Repeat Until succeed 11/19/2018 COMP208 Computers in Engr

20 Hello World (cont.) PROGRaM hello IMPLIcIT NONE
Program name block PROGRaM hello IMPLIcIT NONE WRITE(*,*) "Hello World!" END PROGRaM Later “!” comment the whole line WRITE(*,*): Write something on the screen 11/19/2018 COMP208 Computers in Engr

21 The Program Block PROGRAM hello IMPLICIT NONE !This is my first program WRITE (*,*) “Hello World!“ END PROGRAM hello The bold keywords tell the compiler where the program begins and ends. They bracket a section of code called a block Using uppercase is a convention to distinguish keywords. FORTRAN is case insensitive. PROGRAM, program, proGRAM, pRoGrAm are all the same. 11/19/2018 COMP208 Computers in Engr

22 The Program Block in General
Syntax for the program block PROGRAM program-name IMPLICIT NONE {declarations} {statements} {subprograms} END PROGRAM program-name 11/19/2018 COMP208 Computers in Engr

23 Some specific facts about codes
White space insensitive WRITE(*,*) “Hello world!” WRITE (*, *) “Hello world!” W RITE(*,*) “Hello world!”  compile error case insensitive write(*,*) “Hello world!” Note: These two facts only for codes, not for data WRITE(*,*) “HELLO W O RLD !” same same Different 11/19/2018 COMP208 Computers in Engr

24 A simple example: Roots finding
Finding roots for quadratic aX^2+bX+c=0 Input a, b, c Output root(s): (-b + SQRT(b*b - 4*a*c))/(2*a) (-b - SQRT(b*b - 4*a*c))/(2*a) 11/19/2018 COMP208 Computers in Engr

25 Roots finding (cont.) start Initialize a=1, b=-5, c=6
w = (b*b – 4*a*c) R1 = (-b + sqrt(w))/(2*a) R2 = (-b - sqrt(w))/(2*a) End 11/19/2018 COMP208 Computers in Engr

26 Roots finding (cont.) Declare variables, Must at the head of block
PROGRAM ROOTSFINDING INTEGER a, b, c REAL x, y, z, w, r1, r2 a=1 b=-5 c=6 ! To calculate b*b – 4*a*c x = b*b y = a*c z = 4*y w = x-z r1 = (-b +SQRT(w))/(2*a) r2 = (-b – SQRT(w))/(2*a) WRITE(*, *) r1, r2 END PROGRAM Declare variables, Must at the head of block initialize variables with values statements: calculation statements:Output results 11/19/2018 COMP208 Computers in Engr

27 Roots finding (cont.) Keywords in Fortran90 variables constants
PROGRAM ROOTSFINDING INTEGER a, b, c REAL x, y, z, w, r1, r2 a=1 b=-5 c=6 ! To calculate b*b – 4*a*c x = b*b y = a*c z = 4*y w = x-z r1 = (-b +SQRT(w))/(2*a) r2 = (-b –SQRT(w))/(2*a) WRITE(*, *) r1, r2 END PROGRAM variables operators constants 11/19/2018 COMP208 Computers in Engr

28 Variables and constants
Constants (e.g., 1, -5, 6, 4, 2) A variable (e.g., a, b, c, x, y, z, w) is a unique name which a FORTRAN program applies to a word of memory and uses to refer to it. Naming convention alphanumeric characters (letters, numerals and the underscore character) The first character must be a letter. No case sensitivity Don’t use keywords in Fortran as variables’ names 11/19/2018 COMP208 Computers in Engr

29 Variable data types E.g., a, b, c E.g., x, y, z, w
INTEGER E.g., a, b, c REAL E.g., x, y, z, w LOGICAL COMPLEX CHARACTER Examples: Data type is important INTEGER::a=1,b=-5,c=5 INTEGER r1, r2 IMPLICIT NONE needed to prevent errors. Comment out “IMPLICIT NONE” write(*, *) r1, r3 11/19/2018 COMP208 Computers in Engr

30 Declarations Declarations tell the compiler
PROGRAM RootFinding IMPLICIT NONE INTEGER :: a, b, c REAL :: x,y,z,w REAL :: r1, r2 . . . END PROGRAM RootFinding Declarations tell the compiler To allocate space in memory for a variable What “shape” the memory cell should be (i.e. what type of value is to be placed there) What name we will use to refer to that cell 11/19/2018 COMP208 Computers in Engr

31 Declare variables INTEGER:: a=1, b=-5, c=6 REAL:: x, y, z, w
same 11/19/2018 COMP208 Computers in Engr

32 Variable precision 11111111 KIND BITs Value range 1 8
1 byte = 8 bits INTEGER(KIND=2)::a OR INTEGER(2)::a KIND BITs Value range 1 8 -2**7 < a < +2**7 (i.e., +128) 2 16 -2**15 < a < +2**15 (i.e., ) 4(default) 32 -2**31 < a < +2**31 64 -2**63 < a < +2**63 11/19/2018 COMP208 Computers in Engr

33 Variable precision (cont.)
REAL(KIND=4) CHARACTER KIND=1 only KIND BITs 4(default) 32 8(equivalent to DOUBLE PRECISION) 64 16 8*16 11/19/2018 COMP208 Computers in Engr


Download ppt "Lecture II Basic computer and programming concepts"

Similar presentations


Ads by Google