COA CSE 2009 Module 1 (1)
COA CSE 2009 Module 1 (1)
CSE 2009
2
Computer:
It is fast electronic device that accepts digitized input
information, processes it according to a list of internally stored
instructions and produces the resulting output information.
Computer program:
The list of instructions that performs the task is called a
computer program.
3
Types of Computers
Computers are classified based on size, cost and
computational power.
• Microcomputers
• Mainframes
• Minicomputers
• Servers
• Super computers
4
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.
5
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.
6
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.
7
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.
8
Minicomputer
• A midsized computer, in size and power,
minicomputers lie between workstations and
mainframes.
9
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).
10
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.
11
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
12
Arithmetic
Input and
logic
Memory
Output Control
I/O Processor
13
How information is handled by
computer?
• It is convenient to categorize this information as either instructions or
data.
• Instructions or Machine instructions, are explicit commands that
• govern the transfer of information within a computer as well as between the
computer and its I/O devices.
• Specify the arithmetic & logic operations to be performed.
• Usually programs (set of instructions) is stored in the memory.
Processor then fetches the instructions that make up the program
from the memory, one after the another, and performs the desired
operations.
14
• Computer is completely controlled by the stored
program
• Data are numbers and encoded characters that
are used as operands by the instructions.
•
15
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.
16
Keyboard
17
Mouse
• An input device that allows the user to
manipulate objects on the screen by moving
the device along the surface of a desk.
18
Output Devices
• the output unit is the counterpart of the
input unit.
• Its function is to send processed results
to the outside world.
19
Speakers
20
Printer
21
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
22
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.
23
• 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 location.
• Addresses are numbers that identify successive
locations
• A word address can be used to access the word.
24
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.
25
• 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.
26
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.
27
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.
• Data transfers between processor & memory are also
controlled by CU through timing signals.
• Timing signals are signals that determine when a given action
is to take place.
28
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.
29
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.
30
• 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.
31
Connection Between the Processor and the memory
Memory
MAR MDR
Control
PC R0
R1
Processor
IR
ALU
Rn - 1
n general purpose
registers
32
• Figure shows how the memory and the processor can be
connected.
• Processor contains number of registers used for several
purposes.
33
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.
34
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.
35
• 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.
36
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 ( Data Bus)
Address lines (Address Bus )
control lines. (Control Bus)
37
Bus Structure
38
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.
39
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.
40
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.
41
• So, the total time required to execute the program is affected
by
• Speed of the processor
• Compiler speed
• Disk used
• Speed of output device
• The time needed to execute a instruction is called as
processor time.
• Processor time depends on the hardware involved in the
execution of individual machine instructions.
• This hardware comprises the processor & the memory which
are usually connected by the bus. (diagram in next slide)
42
Performance of a
computer
Main Cache
memory memory Processor
Bus
43
• 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.
44
Processor clock
• Each & every electronic embedded systems should have processor circuit.
• These Processor circuits are controlled by a timing signal called clock.
• The clock defines regular time intervals, called clock cycles.
• Each & every machine instruction is having one or more actions. For ex,
add R0,R1
• 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.
• So clock cycle is an important parameter that affects processor performance.
• The ‘p’ be the length of one clock cycle.
• clock rate is given by R=1/ P, which is measured in cycles per second.
• Generally, processor speed is mentioned in terms of clock rates & it is in
some Giga hertz (G Hz)
45
46
Basic Performance Equation
N S
T
R
47
Basic Performance Equation
• How to improve the performance parameter T?
48
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.
49
• 1.A program has 100 machine instructions in a straight
line code and 100 in a loop which gets executed for 49
times. The average number of basic steps needed to
execute one machine instruction is 2 cycles and the
processor is controlled by a clock of 2GHz. Find the time
required for the program execution?
• N=100+49*100=5000
• S=2
• R=2*10^9
• T=N*S/R=5000*2/2*10^9=5*10^-6
50
• 2. A program contains 1000 instructions. Out of that
25% instruction requires 4clock cycles, 40% requires 5
clock cycles and remaining requires 3 clock cycles for
execution. Find the total time required to execute the
program running in a 1GHz machine?
• N=1000
• R=1*10^9
• T=N*S/R
• T=(250*4+400*5+350*3)/1*10^9
• T=4.050*10^-6
51
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.
52
• 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.
53
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.
54
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.
55
56
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.
57
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.
58
Examples:
59
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.
60
• 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).
61
Memory Locations and Addresses
nbits
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.
62
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
63
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
64
Well, it is impossible to allot a unique address to each bit in memory. As
a solution, most modern computers assign successive addresses to
successive byte locations in memory. This assignment of addresses to
individual byte locations is termed byte addressability and memory is
referred to as byte-addressable memory.
If we assign an address to individual byte locations in the memory like
0, 1, 2, 3….
.Now if the word length of the machine is 16 bit then the successive
words are located at addresses 0, 2, 4, 6… where each word would have
2 bytes of information. Similarly, if we have a machine with a word
length of 32 bit then the successive words are located at the addresses
0, 4, 8, 12… where each word would have 4 bytes of information and it
could store or retrieve 4 bytes of instruction or data in a single and
basic operation.
65
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,…
66
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
67
Big-Endian and Little-Endian Assignments
68
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
69
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.
70
Instruction and Instruction Sequencing
• We know that, program is nothing but an collection of
instructions.
• These instructions may be addition of 2 numbers(some
arithmetic operations), testing for a particular
condition(logical operation), reading a character/data
from the input device, sending a character to be
displayed on the output device.
• So the small steps may be one of these
71
Instruction and Instruction Sequencing
72
Register Transfer Notation
• It is nothing but transfer of data from one part of (location) the
computer to other part(location)
• The possible locations used while transferring data are
• Memory locations
• Processor registers
• Registers in I/O sub-systems
• While writing the programs, generally we store the values in a
variables. These variables are nothing but the name given to some
memory location. It is also known that, every memory location is
having an unique address.
• Most of the time, we identify a location by some name associated with
hardware binary address.
73
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)
74
Assembly Language Notation
• Assembly language notation is another type of notation used
to represent machine instructions & programs
75
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
• Zero-Address Instructions
ADD ;TOS ← TOS + (TOS – 1)
Opcode Operand(s) or Address(es)
77
• In all these instructions, we need to specify the address of
the operands in the instruction.
• But, it is also possible to use instructions in which the
locations of all operands are defined implicitly.
• Such instructions are found in machines that store
operands in a structure called pushdown stack.
• Such type of instructions are called zero address
instructions.
• ADD ;TOS ← TOS + (TOS – 1)
78
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
79
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
Opcode Operand 1, Operand 2, Result
a = b + c;
Disadvantage:-
Format are Not common
Needs very long words to hold everything
80
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
81
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
82
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.
83
84
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.
85
86
Third generation(1965-1975):
87
Fourth generation(1975 to the present):
88
89
End of Module 1
90