Coa Cse 2009 Module 1
Coa Cse 2009 Module 1
CSE 2009
Computer program:
The list of instructions that performs the task is called a
computer program.
2
Types of Computers
Computers are classified based on size, cost and
computational power.
• Microcomputers
• Mainframes
• Minicomputers
• Servers
• Super computers
3
Microcomputer
• The most common computer is
microcomputer.
e.g. Desktop computer.
• Microcomputers are designed to be
used by individuals, whether in the form
of PCs, workstations, or notebook
computers.
• A Microcomputer contains a CPU on a
microchip (the microprocessor).
• Desktop computers have processing and
storage units, display and audio output
units, and keyboard that can all be
located easily on a desk.
• The storage media includes hard-disks,
CD-ROMs.
4
Laptop Computer
• Portable notebook
computers are a
compact version of the
personal computer..
• All components
(keyboard, mouse, etc.)
are in one compact unit.
• Usually more expensive
than a comparable
desktop.
• Sometimes called a
Notebook.
5
Workstation
• Powerful desktop computer designed for specialized tasks.
• It has more computational power than personal computers.
• Workstations are often used in engineering applications.
• Workstations generally come with a large high-resolution
graphics screen.
• Most workstations also have mass storage devices such as disk
drive, but a special type of workstation, called diskless
workstation, comes without a disk drive.
• Like personal computers, most workstations are single-user
computers.
6
Mainframe
• A very large and expensive
computer capable of
supporting hundreds or even
thousands of users
simultaneously.
• Mainframes are mainly Used
to store, manage, and process
large amounts of data.
• Mainframes are used in
medium to large corporations
that require more computing
power and storage capacity
than workstations can provide.
7
Minicomputer
• A midsized computer, in size and power, minicomputers
lie between workstations and mainframes.
8
Server
• Purpose is to
“serve.”
• A computer that
has the purpose
of supplying its
users with data;
usually through
the use of a LAN
(local area
network).
9
Supercomputer
• A Super computers is typically used for scientific and
engineering applications that must handle very large databases
or do a great amount of computation.
• It is used for large- Scale numerical calculations required in
applications such as weather forecasting and aircraft design.
• super computers are fastest, costliest and most powerful
computers.
• It can execute million instructions per second.
• Most super computers are really multiple computers that
perform parallel processing.
10
Functional Units Of Computer
A computer consists of five functionally independent main parts.
• Input unit
• Output unit
• Memory unit
• Arithmetic and logic unit
• Control unit
11
Arithmetic
Input and
logic
Memory
Output Control
I/O Processor
12
Input Devices
• The input unit accepts coded information from users
• The information received is either stored in the
computer’s memory or immediately executed by the
ALU.
• The most well-known input device is the key-board.
• Whenever key is pressed, the corresponding letter or
digit is automatically translated into its
corresponding binary code and transmitted over a
cable to either the memory or the processor.
13
Keyboard
14
Mouse
• An input device that allows the user to manipulate
objects on the screen by moving the device along
the surface of a desk.
15
Output Devices
• the output unit is the counterpart of the
input unit.
• Its function is to send processed results to
the outside world.
16
Speakers
17
Printer
18
Storage Devices
• Used to keep data when the power to the computer is turned off.
• Different forms
• Hard disk
• Floppy or zip disks
• CD-Writer
19
Memory Unit
• The function of memory unit is to store the programs
and data.
• There are two classes of storage
1) Primary Storage
2) Secondary storage
Primary Storage:
• It is a fast memory that operates at electronic speeds.
• Programs must be stored in the memory while they are
being executed.
20
• The memory contains a large number of
semiconductor cells, each capable of storing in one
bit of information.
• Because a single bit represents a very small
amount of information, bits are not handled
individually.
• The memory is organized so that the contents of
one word, containing ‘n’ bits can be stored or
retrieved in one basic operation.
• To provide easy access to any word in the memory,
a distinct address is associated in with each word.
• A word address can be used to access the word.
21
Word Length:
• The number of bits in each word is called as the word
length of the computer.
• Typical word lengths range from 16-64 bits.
Memory Access Time:
• The time required to access one word is called the
memory access time.
• This time is fixed, independent of the location of
the word being accessed.
• It typically ranges from a few nanoseconds (ns) to
about 100 ns.
• The primary memory is also called as main memory.
22
• Primary memories are small in capacities and
expensive.
• Thus additional, cheaper secondary storage is
used when large amounts of data and many
programs have to be stored.
23
Arithmetic And Logic Unit
• It performs the arithmetic operations such as addition,
subtraction, multiplication, division and logic operations
such as AND, OR, Not.
• Suppose two numbers located in the memory are to be
added, they are brought into the processor, and addition is
carried out by the ALU .
• The SUM may then be stored in the memory.
• When the operands are brought into the processor, they
are stored in high-speed storage elements called
registers.
• Each register can store one word of data.
24
Control Unit
• The memory unit, arithmetic and logic and input and
output units store and process information and perform
input and output operations.
• The operation of these units must be coordinated in
some way.
• Control unit coordinates and controls the activities
among the functional units.
• It sends the control signals to other units and senses
their states.
25
The operation of a computer can be summarized as
follows
• The computer accepts information in the form of
programs and data through an input unit and stores it
in the memory.
• Information stored in the memory is fetched, under
program control, into an arithmetic and logic unit,
where it is processed.
• Processed information leaves the computer through an
output unit.
• All activities inside the machine are directed by
control unit.
26
Basic Operational Concepts
• Activity in a computer is governed by instructions.
• To perform a task, an appropriate program consisting of a list
of instructions is stored in the memory.
• Individual instructions are brought from the memory into the
processor, which executes the specified operations.
• Data to be used as operands are also stored in the memory.
e.g. Consider the addition of two operands
Add LOCA, R0
this instruction adds the operand at memory location LOCA
to the operand in a register in the processor, and places the
sum into register R0.
27
• This instruction requires the performance of several steps
1) the instruction is fetched from the memory into the
processor.
2) the operand at LOCA is fetched and added to the contents of
R0.
3) Finally, the sum is placed in register R0.
28
Connection Between the Processor and the memory
Memory
MAR MDR
Control
PC R0
R1
Process or
IR
ALU
Rn - 1
n general purpose
registers
29
• Figure shows how the memory and the processor can be connected.
• Processor contains number of registers used for several purposes.
30
MAR & MDR:
These two registers provide communication with the memory.
Memory address Register: (MAR)
It holds the address of the location to be accessed.
Memory Data Register:
It contains the data to be written into or read out of the addressed
location.
31
Operating steps:
• Execution of program starts when the PC is set to point to the first
instruction of the program.
• The contents of the PC are transferred to the MAR and a read control signal
is sent to the memory.
• After some time, the addressed word is read out of the memory and loaded
into the MDR.
• Next, the contents of the MDR are transferred to the IR.
32
• If operand resides in the memory it has to be fetched by sending
its address to the MAR and initiates read cycle.
• Get operands for ALU
Operand in general-purpose register
Operand resides in Memory (Send its address to MAR – Read
cycle – transfer from MDR to ALU)
• Perform desired operation in ALU
• Store the result back to memory
To general-purpose register
To memory (address to MAR, result to MDR – Write cycle)
• At some point during the execution of the current instruction , the
contents of the PC are incremented so that PC points to the next
instruction to be executed.
33
Bus Structures
• So far we have discussed the functions of individual parts of a
computer.
• To form an operational system. These parts must be connected
in some organized way.
• A group of lines that serves as a connecting path for several
devices is called a BUS.
• Bus contains three sets of lines
Data lines
Address lines
control lines.
34
Bus Structure
35
Bus Structure
• All units are connected to this bus.
• Because bus can be used for only one transfer at a time, only two
units can actively use the bus at any given time.
• The advantage of the single bus-structure is its low cost and its
flexibility for attaching peripheral devices.
• multiple buses can be used to interconnect large number of
devices.
• The devices connected to bus vary widely in their speed of
operation, some devices such as keyboards and printers are
relatively slow.
36
Bus Structure
• Memory and processor operate at high speeds.
• To synchronize the speeds of these devices.
• A common approach is to include buffer registers with the
devices to hold the information during transfers.
37
Performance of a computer
• The most important measure of a computer is how quickly it
can execute the programs.
• The speed with which a computer executes the program is
affected by the design of its hardware and its machine
language instructions.
• Performance of a computer is also affected by the compiler.
• For the best performance, it is necessary to design the
compiler, the machine instruction set, and the hardware in a
coordinated way.
38
Performance of a computer
Main Cache
memory memory Processor
Bus
39
• A program will be executed faster if the movement of
instructions and data between the main memory is
minimized.
• For example, suppose a number of instructions are
executed repeatedly over short period of time, as
happens in the program loop.
• If these instructions are available in the cache memory,
they can be fetched quickly during the period of
repeated use.
40
Processor clock
• Processor circuits are controlled by a timing signal called clock.
• The clock defines regular time intervals, called clock cycles.
• To execute a machine instruction, the processor divides the action to
be performed into sequence of basic steps, such as each step to be
completed in one clock cycle.
• The length ‘p’ of one clock cycle is an important parameter that
affects the processor performance.
• Its inverse is the clock rate, R=1/ P, which is measured in cycles per
second.
• Hertz – cycles per second
41
42
Basic Performance Equation
N S
T
R
• T – processor time required to execute a program that has been
prepared in high-level language
• N – number of actual machine language instructions needed to
complete the execution (note: loop)
• S – average number of basic steps needed to execute one machine
instruction. Each step completes in one clock cycle
• R – clock rate
• Note: these are not independent to each other
43
Basic Performance Equation
• How to improve the performance parameter T?
44
Possibilities for increasing the clock rate
1.Improving the integrating –circuit (IC) technology makes
logic circuits faster, which reduces the time needed to
complete a basic step. this allows the clock period ‘p’ to be
reduced and the clock rate ’R’ to be increased.
45
Number Representation
• Computers are built using logic circuits that operate on
information represented by two valued electrical signals. We
label the two values as 0 and 1.
46
• We obviously need to represent both positive and negative
numbers.
• Three systems are used for representing such numbers.
1. Sign- and –magnitude.
2. 1’ s Complement.
3. 2’s Complement.
• In all three systems, the left most bit is 0 for positive numbers
and 1 for negative numbers.
47
Sign- and - magnitude:
• In sign and magnitude system, negative values are represented
by changing the most significant bit from 0 to 1 in the b vector
of the corresponding positive value.
For example +5 is represented by 0101, and -5 is
represented by 1101.
1’s complement:
• In 1’s complement representation, negative values are obtained
by complementing each bit of the corresponding positive value.
Thus, the representation for -3 is obtained by complementing
each bit in the vector 0011 to get 1100.
48
2’ s complement :
• In 2’s complement, negative values are obtained by adding 1 to
the 1’s complement of that number.
• 2’s complement is the most efficient way to carry out addition
and subtraction operations.
• It is one most often used in computers.
49
50
Addition and subtraction of signed numbers
Addition:
• To add two signed numbers , add their n- bit
representations , ignoring the carry-out signal from the most
significant bit (MSB) position.
• The sum will be algebraically correct value in the 2’s
complement representation as long as the answer is in the
range -2n-1 through +2n-1 -1.
51
Subtraction of signed numbers:
• To subtract two numbers X and Y, that is to perform X-Y, form
the 2’s complement of Y and then add it to X, the result will be
the algebraically correct value in the 2’s complement
representation system if the answer is in the range
-2n-1 through +2n-1-1.
52
Examples:
53
Overflow in integer arithmetic
• In the 2’s complement number representation system, n bits can represent
values in the range -2n-1 through +2n-1-1. for example, using four bits, the
range of numbers that can represented is -8 through +7.
• When the result of an arithmetic operation is outside regrettable range, an
overflow has occurred.
For example, when using 4- bit signed numbers, if we try to add the numbers
+7 and +4, the output sum vector , S, is 1011. which is code for -5, an
incorrect result.
Similarly, if we try to ad -4 and -6, we get S= 0110= +6, another incorrect
result
• Thus , overflow may occur if both summands have the same sign.
54
• A simple way to detect overflow is to examine the signs of the
two summands X and Y and the sign of the result. When both
operands X and Y have the same sign, an overflow occurs when
the sign of S is not the same as the signs of X and Y.
Characters :
• In addition to numbers computers must be able to handle
nonnumeric text information consisting of characters.
Characters can be letters of the alphabet, punctuation marks,
and so on.
• They are represented by codes that usually eight bits long.
• One of the most widely used codes is the American Standards
Code for Information Interchange (ASCII).
55
Memory Locations and Addresses
n bits
first word
• How the memory is second word
organized?
• Memory consists of many •
millions of storage cells, each •
•
of which can store 1 bit. ith word
• Data is usually accessed in n-
bit groups. n is called word
length. •
•
•
last word
Memory words.
56
Memory Locations and Addresses
• 32-bit word length example
32 bits
b 31 b 30 b1 b0
•
•
•
Sign bit: b 31= 0 for positive numbers
b 31= 1 for negative numbers
57
Memory Locations and Addresses
• To retrieve information from memory, either for one word
or one byte (8-bit), addresses for each location are needed.
• A k-bit address memory has 2k memory locations using
numbers from 0 – 2k-1 as the addresses of successive
locations in the memory.
• 2k addresses constitute the address space of the computer.
• 24-bit memory: 224 = 16,777,216 = 16M (1M=220)
• 32-bit memory: 232 = 4G (1G=230)
• 1K(kilo)=210 1T(tera)=240
58
Memory Locations and Addresses
Byte Addressability
• It is impractical to assign distinct addresses to
individual bit locations in the memory.
• The most practical assignment is to have successive
addresses refer to successive byte locations in the
memory – byte-addressable memory.
• Byte locations have addresses 0, 1, 2, … If the word
length is 32 bits, successive words are located at
addresses 0, 4, 8,…
59
Big-Endian and Little-Endian Assignments
Big-Endian: Lower byte addresses are used for the most significant bytes of the word
Little-Endian: Lower byte addresses are used for the less significant bytes of the word
Word
address Byte address Byte address
0 0 1 2 3 0 3 2 1 0
4 4 5 6 7 4 7 6 5 4
• •
• •
• •
k k k k k k k k k k
2 -4 2 -4 2 -3 2- 2 2 - 1 2 - 4 2- 1 2 - 2 2 -3 2 -4
60
Big-Endian and Little-Endian Assignments
61
Memory Locations and Addresses
Word Alignment
• Words are said to be aligned in memory if they
begin at a byte address. that is a multiple of the num
of bytes in a word.
• 16-bit word: word addresses: 0, 2, 4,….
• 32-bit word: word addresses: 0, 4, 8,….
• 64-bit word: word addresses: 0, 8,16,….
• Access numbers, characters, and character strings
62
Memory Operation
• Load (or Read or Fetch)
Transfers a copy of the contents of a specific memory location to the processor.
The memory content doesn’t change.
Processor send the address of the desired location to the memory and request its
contents to be read.
The memory reads the data and send them to the processor.
• Store (or Write)
Transfers an item of information from the processor to a specific memory
location.
The former contents of that location is overwritten.
The processor sends the address of the desired location to the memory along
with the data to be written.
63
Instruction and Instruction Sequencing
• “Must-Perform” Operations
Data transfers between the memory and the
processor registers
Arithmetic and logic operations on data
Program sequencing and control
I/O transfers
64
Register Transfer Notation
• Identify a location by a symbolic name standing for its
hardware binary address
Ex: For memory location: LOC,PLACE,A,VAR2
For processor registers: R0,R1
For I/O registers: DATAIN, OUTSTATUS
• Contents of a location are denoted by placing square brackets
around the name of the location
Ex: R1←[LOC]
R3 ←[R1]+[R2]
• This type of notation is known as Register Transfer Notation
(RTN)
65
Assembly Language Notation
• To represent machine instructions and programs.
66
RISC and CISC Instruction Sets CISC versus RISC
CISC- Complex Instruction Set Computer
RISC- Reduced Instruction Set Computer
CISC RISC
Instructions can take several
Single cycle instructions
clock cycles
Complex and variable length Simple standardized
instructions instructions
68
Basic Instruction Types
Example: Evaluate C=A+B
• Three-Address ADD A, B, C
• Two-Address ADD A,B [OR] MOVE A,R1
MOVE B,C ADD B,R1
MOVE R1,C
• One-Address LOAD A
ADD B
STORE C
69
Basic Instruction Types
Example: Evaluate E=(A+B) (C+D)
• Three-Address
ADD A, B, R1 ; R1 ← M[A] + M[B]
ADD C, D, R2 ; R2 ← M[C] + M[D]
MUL R1, R2, E ; M[E] ← R1 R2
3 addresses
Operand 1, Operand 2, Result
a = b + c;
Disadvantage:-
Format are Not common
Needs very long words to hold everything
70
Basic Instruction Types
Example: Evaluate E=(A+B) (C+D)
• Two-Address
MOV A, R1 ; R1 ← M[A]
ADD B, R1 ; R1 ← R1 + M[B]
MOV C, R2 ; R2 ← M[C]
ADD D, R2 ; R2 ← R2 + M[D]
MUL R1, R2 ; R2 ← R1 R2
MOV R2,E ; M[E] ← R2
Advantage:-
Reduces length of instruction
Requires some extra work
Temporary storage to hold some results
MOVE operation required
71
Basic Instruction Types
Example: Evaluate E=(A+B) (C+D)
• One-Address
LOAD A ; AC ← M[A]
ADD B ; AC ← AC + M[B]
STORE R1 ; R1 ← AC
LOAD C ; AC ← M[C]
ADD D ; AC ← AC + M[D]
MUL R1 ; AC ← AC R1
STORE E ; M[E] ← AC
Advantage
1.More primitive
2.Require less complex processor
3.Shorter Instruction length
72
Generations of computers
First Generation (1945-1955):
• The key concept of a stored program was introduced by
John von Neumann.
• Programs and their data were located in the same
memory , as they are today.
• Assembly language was used to prepare programs and
was translated into machine language for execution.
• Basic arithmetic operations were performed in a few
milliseconds using vacuum tube technology.
• Magnetic core memories and magnetic tape storage
devices were also developed.
73
74
Second generation(1955 – 1965):
• The invention of Transistors marked the start of the second
generation.
• Magnetic core memories and magnetic drum storage devices
were more widely used in the second generation.
• High level languages, such as Fortran were developed, making
preparation of programs much easier.
• System programs called compilers were developed to
translate these high level language programs into
corresponding assembly language program.
• Separate I/O processors were developed that could operate
in parallel with the central processor.
• IBM became a major computer manufacturer during this
time.
75
76
Third generation(1965-1975):
77
Fourth generation(1975 to the present):
78
79
End of Module 1
80