EE1005 L01 Computers & Programming
EE1005 L01 Computers & Programming
Thinking to Programming
Lesson 1
Computers & Programming
(Reference: Harry H. Cheng, Chapter 1)
Instructions &
Data Storage
in Memory
Keyword: programmable
1-2
Computer Systems
1. Hardware: monitor,
keyboard, etc.
2. Software: Collections of
instructions for the
Personal Computer (PC)
computer to execute
(programs).
1-3
Hardware Components
• Main Memory (Primary Storage)
- on Main Board
• Input Devices
• Output Devices
http://www.youtube.com/watch?v=S6-5FCv7-_g 1-4
Main Memory (1)
To store
• instructions to be executed,
• data to be manipulated,
• processing results.
1-5
Main Memory (2)
Think of main memory as a collection of boxes
(cells). Each cell can hold 1 byte of data and
has a unique address (an integer value).
Address Contents
100000
‘Logical’ Cell
100001 3.14159 Size is
100002 greater than
100003 1 byte
100004 H
Cell Size of
100005 I 1 byte each
1-6
Main Memory (3)
As each memory cell can be accessed directly,
main memory is also known as Random
Access Memory (RAM).
1-8
Read-Only Memory
ROM (Read-Only Memory) stores data
permanently. Usually, they can only be read from
but not written to. The data are physically
encoded in the circuit, so they cannot be modified
easily, if at all.
1-9
CPU Components
Registers M
Data, e
Control Address, m
Unit Control
Buses o
r
ALU
y
1-10
ALU
The ALU (Arithmetic Logic Unit) is a
fundamental component of the CPU, and it
can perform:
1-11
Registers & Control Unit
Control Unit:
It controls flow of instructions and data from
and to memory, and inside the CPU. It tells
the ALU what operation to perform on the
data.
Registers:
These are memory cells in the CPU that allow
very rapid access of instructions and data by
the ALU and the Control Unit.
1-12
Secondary Storage & I/O Devices
For cheap and permanent storage of data.
Examples:
• Hard disks
• Flash drives
• CD-R, CD-RW, DVD, DVD-RW
• Magnetic tapes
1-13
Flash Memory
1-14
Interaction Between CPU,
RAM and Hard Disk
RAM
2a.One instruction and associated
3a.Final results are
data are fetched from RAM to
either shown on
CPU at any one time
screen or saved
CPU B to Hard Disk
3b.Program and data
U released to Hard
2b.ALU computes and stores
intermediate results in S Disk when
terminated
registers in CPU
2c.Final results are
transferred back to 1. Program and data
RAM transferred to RAM
Example: Executing a
Hard Disk
program on a data file 1-15
System Software
Two major types of software: (i) System
Software; (ii) Application Software.
1-17
Application Software
Software that are very useful to most users.
Examples are:
1-18
What is Programming?
1-19
Programming Languages
A programming language is an artificial
language with a set of special words
(keywords) and a set of rules (syntax or
grammar).
1-20
Machine Language
Each CPU has a set of instructions designed
and manufactured into it.
These machine instructions are different for
CPUs from different chip design companies.
They consist of sequences of 0s and 1s.
1-22
High-Level Languages (Examples)
There are numerous high-level languages.
Common ones are:
1-23
Language Standard
Each major high-level language has a
language standard that describes its syntax
(grammar).
1-24
The Programming Process
1. Problem Solving:
(a) Problem Specification
(b) Problem Analysis
(c) Algorithmic Design (Solution Procedures)
2. Implementation
(a) Coding
(b) Testing
(c) Maintenance
1-25
Algorithm
An algorithm is a set of precisely stated, finite
sequence of executable steps for solving a
problem.
*
1-26
You will learn more in EE2008 DATA STRUCTURES
& ALGORITHMS
Pseudocode Example 1
INPUT radius
circle_area=3.14159*radius*radius
OUTPUT circle_area
1-27
Pseudocode Example 2a
1-28
Pseudocode Example 2b
OUTPUT max
1-29
Pseudocode Example 3
To calculate and display the distances travelled by a
particle falling under gravity from an initial time 0 to a
given point in time. Assume zero initial velocity.
Compute and
distance = 0.5*accel*time*time
display time and
associated PRINT time, distance
distance travelled
1-33
Errors (Bugs) in Programs
A bug is an error in software/hardware.
Correcting a bug is known as debugging. The
following types of errors may appear in our
programs:
Syntax Errors
Summary
1. Computer hardware components
• Main memory, CPU, secondary storage
2. Computer software
• System and Application software
• Programming Language: Low Level and
High Level
• Algorithm and Pseudocode
• Edit, Compile and Link Cycle
• Errors (bugs)
1-35