# Programming

Document Sample

```					Chapter 1
Introduction

1
Objective

Ø Computer Science 可以把它當成是一門與電腦相
關的學科。為了要瞭解電腦的運作，我們把電腦
想像成一個黑盒子，想要嘗試去瞭解電腦共通的
特徵，例如電腦中一定要有那一些元件，分別負
責甚麼功能，好像在做模型一樣。
Ø 這個電腦共通的模型，稱為von Neumann model
。這個章節我們就要先瞭解甚麼是von Neumann
model，並在後面的章節中一一再詳述所有的概
念。
2
Outlines
Ø The Computer as a Black Box
Ø Von Neumann Model
Ø Computer Hardware
Ø Data
Ø Computer Software
Ø History
Ø Key Terms
Ø Summary
Ø Practice Set
3
Ø Homework
Section 1.1
The Computer as a Black Box

4
Computer as a Black box

Ø Computer science as “issues related to the
computer”
Ø Look a computer as a black box
Ø How to define the job performed by this box?
Ø Two common computer model:
• Data processor
• Programmable data processor

5
Data Processor Model

Ø A computer acts as a black box
• Accept input data
• Process the data
• Create output data
• It is too general.
• It does not specify the type of processing.

Input             Computer             Output
Data                                   Data
6
Programmable Data Processor
Model
Ø A program is a set of instructions that tells
the computer what to do with data.
Ø A program is a set of instructions written in a
computer language.

Program

Input            Computer          Output
Data                               Data
7
Example: C Language
#include <iostream>
using namespace std;
main( )
{
int a=0,b=0,c=0 ; /* variable declaration */
cin >> a;          /* read input */
cin >> b;
c=a+b;             /* variable operation */
cout << c ;       /* output to screen */
}
8
Same Program, Different Data

Sort   Program

Input Data       Computer           Output Data
3, 12, 8, 22                        3, 8, 12, 22

Sort   Program

Input Data       Computer           Output Data
14, 6, 8, 12                        6, 8, 12, 14   9
Same Data, Different Program
Sort Program

Input Data     Computer          Output Data
3, 12, 8, 22                     3, 8, 12, 22

Input Data     Computer          Output Data
3, 12, 8, 22                     45
SmallestProgram

Input Data     Computer          Output Data
3, 12, 8, 22                     3              10
Same Program, Same Data

Sort   Program

Input Data        Computer           Output Data
3, 12, 8, 22                         3, 8, 12, 22

11
Comparison of Two Models

Ø Data processor
• It represents a specific-purpose computer.
• Sometime, we call it as processor.
Ø Programmable data processor
• Computers are general-purpose machines.
Ø In Section 1.2, we will try to use von
Neumann model to find:
How does a general-purpose computer work?

12
Section 1.2
Von Neumann Model

13
Von Neumann Model

Ø Every computer today is based on the von
Neumann model.
• John von Neumann
Ø Basic on three ideas:
• Four subsystems
• Stored program concept
• Sequential execution of instructions

14
Four Subsystems (1/2)

Ø Memory: storage area
Ø Arithmetic Logic Unit (ALU): perform
arithmetic and logic operations
Ø Input/Output (I/O): accept input data and
send output data
Ø Control Unit: control the operations of the
memory, ALU and I/O.

15
Four Subsystems (2/2)

Program

Input/Output
Input                                   Output
Data      Arithmetic                    Data
Logic Unit
Memory
Control
Unit
16
Stored Program Concept

Ø Both the data and programs stored in
memory.
Ø Program and data should have the same
format because they are stored in the same
memory.

Program
memory
Data
17
Sequential Execution of
Instructions
Ø A program is made of a finite number of
instructions.
Ø The instructions are executed one after
another.
Ø The control unit                        Fetch
• Fetches one instruction from memory
• Interpret it (decode)

e

D
ut
• Execute it

ec
c

o
xe

de
E
Instruction Cycle        18
Real Computer

Ø Von Neumann model is just a model!
Ø How to realize a computer?
Ø There are 3 components in a computer:
• Computer Hardware in Section 1.3
• Computer Software (Program) in Section 1.5
• Data in Section 1.4

19
Section 1.3
Computer Hardware

20
Computer Hardware

Ø A physical computer must contains all
components in von Neumann model.
Ø We will discuss computer hardware in
Chapter 5.

21
Computer Network

Ø How to communicate 2 computers?
Ø See Chapter 6

22
Section 1.4
Data

23
Storing Data (1/2)

Ø How to store data in memory?
Ø Computer processing is performed by
electronic devices, which are switches with
only two possible states: on and off.
• If the electrical signal is in a storage device
(presence), it is assigned a value of 1 and it is on.
• If the electrical signal is not in a storage device
(absence), it is assigned a value of 0 and it is off.
• Two states (binary: 0/1)
Ø Storage is a binary world!                            24
Storing Data (2/2)

Ø How to store different types of data as a
binary pattern?
• Ex: 2 v.s. 00000010 in 2’ complement
• Ex: 4 v.s. 00000100 in 2’ complement
• Ex: 100 v.s. 01100100 in 2’ complement
Ø How data are manipulated as a binary
pattern?
• Ex: Binary addition / subtraction / logical operation
• Ex: 2+2=4 v.s. 010+010=100
Ø Answers are in Chapters 2,3,4.                        25
Data Organization

Ø Data outside a computer can take many
forms.
Ø Data is stored in binary form inside a
computer.
• Data are organized into small units.
• Small units organized into larger units.
Ø Answers are in Chapters 11-14: data
structure, abstract data structure, file
structure, database.
26
Section 1.5
Computer Software

27
Computer System

28
Programming

Ø The main feature of the von Neumann model
is the concept of the stored program.
Ø Two aspects of programming:
• A sequence of instructions
• Programs must be stored (into the memory when
they run!)
Ø See Chapter 9

29
Program and Data in Memory

Ø Memory is used to hold data and program.

Program

main   Program
memory

Data                            30

Ø Why a program must be made of instruction?
• Basic instructions are provided by computer
hardware.
• Programmers combine these instructions to

cin >> A;
cin >> B;           Program to find the
C=A+B;              summation of two integer
cout << C;                                         31
Algorithm

Ø How to write a program by a programmer?
•   Solve the problem in a step-by-step manner.
•   Try to find the appropriate instructions and
combine them as a program
Ø The step-by-step solution is called an
algorithm. (See Chapter 8)
1. Input first data item into memory. (call it as A)
2. Input second data item B into memory. (call it as B)
3. Add the two together and store the result in memory.
4. Output the result.
32
Algorithm to find the summation of two integer
Computer Languages

Ø Machine language: 0 and 1 only!
Ø Computer language: the idea of using
symbols to represent binary patterns
• Ex: C language, Java
Ø Compare to Natural language:
• Computer language has more limited number of
symbols, and a limited number of words.
• Ex: read from standard input v.s. cin >>
• Ex: print out to standard output v.s. cout <<   33
Software Engineering

Ø Software engineering is the design and
writing of structured programs.
Ø The program must follow strict principles and
rules.
• Ex: True is 1, False is 0.
• Ex: Analysis → Design → Prototype → Test → A
large scale product
• Ex: Full documents
Ø See Chapter 10.
34
System Development

Define System    Create       Use           Modify
Specification   Prototype   Prototype      Prototype

User           User
OK?       no suggestion
yes
Develop
Real
System                 35
Operating System (OS)

Ø There are a series of instructions (tasks)
common to all programs. It is not necessary
to write the same tasks in all programs.
• Ex: receive data from keyboard
Ø The operating system originally worked as a
manager to facilitate access of the computer
components for a program.
• Ex: Windows, Unix, FreeBSD
Ø See Chapter 7.
36

Ø Chapter 15: data compression
Ø Chapter 16: security
Ø Chapter 17: theory of computation

37
Data Compression

Run-Length   MPEG frames   38
Security
Secret Key Encryption

Public Key
Encryption

39
Theory of Computation

Turing Machine
40
Section 1.6
History

41
The History of Computing and
Computer
Ø There are three periods:
Ø Mechanical machines (before 1930)
Ø Birth of electronic computer (1930-1950)
• Early electronic computers
• Computers based on von Neumann model
Ø Computer generations (1950-present)
• First to Fifth generations

42
Computer
vacuum
Ø Mechanical (1896)
tube
Ø Mechanical + Electrical (1930)
Ø Vacuum Tube (1944)
Ø Transistors (1959)
Ø Integrated Circuit (IC) (1967)
Ø Storages (CD-ROM, DVD)

transistor
IC
43
Mechanical Machines

Ø Abacus
Ø Based on the technology of gears
•   Blaise Pascal (1623-1662) =
•   Gottfriedn Wilhelm Lebniz (1646-1716)
•   Joseph-Marie Jacquard’s loom (1801) =
•   Charles Babbage (1792-1871) =
ü Difference Engine
ü Analytic Engine: all components in von Neumann model
ü Augustra Ada Byron: First Programmer in the world
• Herman Hollerith (1860-1929)
44
ü Automatic read/write data from/to punched cards
Pascal’s Machine

45
Jacquard Loom

Ø The first machine
used the idea of
store and
programming!

46
Babbage’s Machines

Difference Engle

Analytical Engine                      47
Birth of Electronic Computers (1/2)

Ø Electronic + mechanical machine
• Howard Aiken & IBM’s Maker I (1930s) =
Ø Digital computer with vacuum tube
• John Atanasoff & Clifford Berry’s Atanasoff-Berry
Machine: ABC, first special-purpose electrical
computer (1939)
• 1946, ENIAC, first general-purpose electronic
computer =
• Alan Turing’s COLOSSOS
48
Birth of Electronic Computers (2/2)

Ø Above machines:
• Memory only for storing data
• Programmed externally by using wires or switch
Ø The first computer based on von Neumann
model is Pennsylvania’s EDVAC (1950).
Ø At the same time, Cambridge’s EDSAC is
created by Maurice Wilkes.
Ø After 1950, almost computers are following
the von Neumann model.
49
Mark I

Ø Begin at 1937, Finished at 1944
• Work with IBM
• Idea come from Babbage

50
The Mark I Computer, completed
in 1940 at Harvard University

51
ENIAC

“Where... the ENIAC is equipped with 18,000 vacuum tubes and weighs 30 tons,
computers in the future may have 1,000 vacuum tubes and perhaps weigh just 1-   52
1/2 tons.”          Popular Mechanics, March 1949, p.258
Computer Generations (1950-
Present)
Ø First Generation (roughly 1950-1959)
• Commercial computers, professionals, Mainframe
Ø Second Generation (roughly 1959-1965)
• Transistors, FORTRAN, COBOL
Ø Third Generation (roughly 1965-1975)
• Integrated circuit (IC), Minicomputer, software packet
Ø Forth Generation (roughly 1975-1985)
• VLSI, Microcomputer, computer network
Ø Fifth Generation (started in 1985)
53
• Laptop, storage, multimedia, virtual reality
Technology Trends

ØProcessing
ØIntegration
• Single-chip systems
ØCommunication
• Optical and wireless
ØStorage density - CDROM, DVD etc

54
Market Trend - “Consumer
Friendly”
ØVisual Communication
• 3D sounds and images
ØInternet Explosion
• Information and communication
ØInformation Appliances
• Personal organizers
• Mobile phones
• Wearable computers

55
A Growing Industry

Ø In 2008, there are 109 desktop computers or
notebooks in the world.
• The growth rate is about 12%.
• In 2014, there are 2×109 PC in the world.
Ø 科技產業資訊室
• http://cdnet.stpi.org.tw/techroom.htm

56
Section 1.7
Key Terms

57
Key Terms (1/2)

Ø How many terms can you describe?
•   Algorithm
•   Arithmetic logic unit (ALU)
•   Black box
•   Computer language
•   Computer Science
•   Control unit
•   Data processor
•   Input data
•   Instruction                    58
•   Integrated circuit
Key Terms (2/2)

Ø How many terms can you describe?
•   Memory
•   Microcomputer
•   Operating system
•   Output data
•   Program
•   Programmable data processor
•   Software
•   Software engineering
•   Von Neumann model              59
Section 1.8
Summary

60
Summary (1/3)

Ø Computer science means issues related to a
computer.
Ø A computer is a programmable data
processor that accepts input data and
programs and outputs data.
Ø A program is a set of instructions executed
sequentially that tells the computer what to do
with data.
Ø Every computer today is based on the von
Neumann model.                                61
Summary (2/3)

Ø The von Neumann model specifies
•   A memory subsystem
•   An arithmetic logic unit subsystem
•   A control unit subsystem
•   An input subsystem
•   An output subsystem

62
Summary (3/3)

Ø Data and programs are stored in computer
memory.
Ø A step-by-step solution to a problem is called
an algorithm.
Ø A program is written in a computer language.
Ø Software engineering is the design and
writing of programs in a structured form.

63
Practice Set

Ø Review Questions
Ø Multiple-Choice Questions
Ø Exercises

64
Homework

Ø Review Questions: 5,6,7,8,9,11
Ø Multiple-Choice Questions: 12-26
Ø Exercises: 32, 33

65

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 0 posted: 3/14/2014 language: Unknown pages: 65