Basic Structure of Computers, Instructions &programs: Digital Design and Computer Organization BCS302)
Basic Structure of Computers, Instructions &programs: Digital Design and Computer Organization BCS302)
MODULE – 3
Basic Structure of Computers, Instructions &Programs
Topics:
Functional Units
Basic Operational Concepts
Bus Structures
Performance –Processor Clock
Basic Performance Equation
Clock Rate
Performance Measurement.
Memory Location and Addresses
Memory Operations
Instructions and Instruction Sequencing
Addressing Modes
Introduction
Computer Organization explains the function and design of the various units of digital
computers that store and process information.
It also deals with the input units of the computer which receive information from external
sources and the output units which send computed results to external destinations.
The input, storage, processing, and output operations are governed by a list of instructions
that constitute a program.
It deals about computer hardware and computer architecture.
Computer hardware consists of electronic circuits, magnetic and optical storage devices,
displays, electromechanical devices, and communication facilities.
Computer architecture encompasses the specification of an instruction set and the functional
behavior of the hardware units that implement the instructions
Functional Units
A computer consists of five functionally independent main parts: input, memory,
arithmetic and logic, output, and control units, as shown in Figure 1.1.
The input unit accepts coded information from human operators using devices such
as keyboards, or from other computers over digital communication lines.
The information received is stored in the computer‟s memory, either for later use or
to be processed immediately by the arithmetic and logic unit.
The processing steps are specified by a program that is also stored in the
memory.
Finally, the results are sent back to the outside world through the output unit.
Microphones can be used to capture audio input which is then sampled and converted
into digital codes for storage and processing.
Similarly, cameras can be used to capture video input.
Digital communication facilities, such as the Internet, can also provide input
to acomputer from other computers and database servers.
Primary memory, also called main memory, is a fast memory that operates at electronic
speeds.
Programs must be stored in this memory while they are being executed.
The memory consists of a large number of semiconductor storage cells, each capable of
storing one bit of information. These cells are rarely read or written individually.
The memory is organized so that one word can be stored or retrieved in one basic
operation.
The number of bits in each word is referred to as the word length of the computer,
typically 16, 32, or 64 bits.
To provide easy access to any word in the memory, a distinct address is associated with
each word location.
Addresses are consecutive numbers, starting from 0, that identify successive locations.
A particular word is accessed by specifying its address and issuing a control command to
the memory that starts the storage or retrieval process.
Instructions and data can be written into or read from the memory under the control of the
processor.
It is essential to be able to access any word location in the memory as quickly as possible.
A memory in which any location can be accessed in a short and fixed amount of time after
specifying its address is called a random-access memory (RAM). The time required to
access one word is called the memory access time. This time is independent of the
location of the word being accessed.
It typically ranges from a few nanoseconds (ns) to about 100 ns for current RAM units.
Cache Memory
As an adjunct to the main memory, a smaller, faster RAM unit, called a cache, is used
to hold sections of a program that are currently being executed, along with any
associated data.
The cache is tightly coupled with the processor and is usually contained on the same
integrated-circuit chip.
All program instructions and any required data are stored in the main memory.
As execution proceeds, instructions are fetched into the processor chip, and a copy of
each is placed in the cache.
When the execution of an instruction requires data located in the main memory,
thedata are fetched and copies are also placed in the cache.
Secondary Storage
Primary memory is essential, it tends to be expensive and does not retain information
when power is turned off.
Thus additional, less expensive, permanent secondary storage is used when large
amounts of data and many programs have to be stored, particularly for information
that is accessed infrequently.
Access times for secondary storage are longer than for primary memory.
A wide selection of secondary storage devices is available, including magnetic disks,
optical disks (DVD and CD), and flash memory devices.
Output Unit
o The output unit is the counterpart of the input unit.
o Such printers may generate output at speeds of 20 or more pages per minute.
o However, printers are mechanical devices, and as such are quite slow
compared tothe electronic speed of a processor.
o Some units, such as graphic displays, provide both an output function, showing text
o and graphics, and an input function, through touchscreen capability.
Control Unit
The memory, arithmetic and logic, and I/O units store and process information and
perform input and output operations.
The control unit is effectively the nerve center that sends control signals to
other units and senses their states.
Control circuits are responsible for generating the timing signals that govern the
transfers and determine when a given action is to take place.
Data transfers between the processor and the memory are also managed by the
control unit through timing signals.
The contents of memory location LOCA and Register R0 before and after the execution of this
instruction is as follows
Where R1 is Source Operand-1, R2 is the Source Operand-2 and R3 is the Destination. This
instruction adds the contents of Register R1 with the contents of R2 and the result is placed in R3
Register.
The symbolic representation of this instruction is
R3 [R1] + [R2]
The contents of Registers R1,R2,R3 before and after the execution of this instruction is as follows.
Before instruction execution After instruction execution
R1 = 24H R1 = 24H
R2 = 34H R2 = 34H
R3 = 38H R3 = 58H
1. MAR
It establishes communication between Memory and Processor
It stores the address of the Memory Location as shown in the figure.
MAR
Memory
5000h 5000 23h
5001 43h
5002 78h
5003 65h
2. MDR
It also establishes communication between Memory and the Processor.
It stores the contents of the memory location (data or operand), written into or read from
memory as shown in the figure.
MDR
Memory
23h 23h 5000
43h 5001
78h 5002
65h 5003
3. CONTROL UNIT
It controls the data transfer operations between memory and the processor.
It controls the data transfer operations between I/O and processor.
It generates control signals for Memory and I/O devices.
4. PC (PROGRAM COUNTER)
It is a special purpose register used to hold the address of the next instruction to be
executed.
The contents of PC are incremented by 1 or 2 or 4, during the execution of current
instruction.
The contents of PC are incremented by 1 for 8 bit CPU, 2 for 16 bit CPU and for 4 for 32
bit CPU.
R0
R1
R2
.
Rn-1
It consists of set of registers.
A register is defined as group of flip flops. Each flip flop is designed to store 1 bit of
data.
It is a storage element.
It is used to store the data temporarily during the execution of the program(eg: result).
It can be used as a pointer to Memory.
The Register size depends on the processing speed of the CPU
EX: Register size = 8 bits for 8 bit CPU
5. IR (INSTRUCTION REGISTER
It holds the instruction to be executed. It notifies the control unit, which generates timing
signals that controls various operations in the execution of that instruction.
2. BUS STRUCTURE
Bus is defined as set of parallel wires used for data communication between different parts of
computer. Each wire carries 1 bit of data. There are 3 types of buses, namely
1. Address bus
2. Data bus and
3. Control bus1.
1. Address bus :
It is unidirectional.
The processor (CPU) sends the address of an I/O device or Memory device by means of
this bus.
2. Data bus
It is a bidirectional bus.
The CPU sends data from Memory to CPU and vice versa as well as from I/O to CPU
and vice versa by means of this bus.
3. Control bus:
This bus carries control signals for Memory and I/O devices. It generates control signals
for Memory namely MEMRD and MEMWR and control signals for I/O devices namely IORD
and IOWR.
The I/O devices, Memory and CPU are connected to this bus is as shown in the figure.
It establishes communication between two devices, at a time.
3. PERFORMANCE
The performance of a Computer System is based on hardware design of the processor and
the instruction set of the processors.
To obtain high performance of computer system it is necessary to reduce the execution
time of the processor.
Execution time: It is defined as total time required executing one complete program.
The processing time of a program includes time taken to read inputs, display outputs,
system services, execution time etc.
The performance of the processor is inversely proportional to execution time of the
processor.
More performance = Less Execution time.
Less Performance = More Execution time.
CACHE MEMORY: It is defined as a fast access memory located in between CPU and
Memory. It is part of the processor as shown in the fig
The processor needs more time to read the data and instructions from main memory
because main memory is away from the processor as shown in the figure. Hence it slowdown the
performance of the system.
The processor needs less time to read the data and instructions from Cache Memory
because it is part of the processor. Hence it improves the performance of the system.
PROCESSOR CLOCK: The processor circuits are controlled by timing signals called as Clock.
It defines constant time intervals and are called as Clock Cycles. To execute one instruction there
are 3 basic steps namely
1. Fetch
2. Decode
3. Execute.
The processor uses one clock cycle to perform one operation as shown in the figure
Clock Cycle → T1 T2 T3
Instruction → Fetch Decode Execute
The performance of the processor depends on the length of the clock cycle. To obtain high
performance reduce the length of the clock cycle. Let „ P ‟ be the number of clock cycles generated
by the Processor and „ R „ be the Clock rate .
The contents of memory location can be accessed for read and write operation. The memory is
accessed either by specifying address of the memory location or by name of the memory location.
Address space : It is defined as number of bytes accessible to CPU and it depends on the
number of address lines.
5. BYTE ADDRESSABILITY
Each byte of the memory are addressed, this addressing used in most computers are called byte
addressability. Hence Byte Addressability is the process of assignment of address to successive
bytes of the memory. The successive bytes have the addresses 1, 2, 3, 4………….2 n-1. The
memory is accessed in words.
In a 32 bit machine, each word is 32 bit and the successive addresses are 0,4,8,12,… and
so on.
Address 32 – bit word
In this technique lower byte of data is assigned to higher address of the memory and higher
byte of data is assigned to lower address of the memory.
The structure of memory to represent 32 bit number for big endian assignment is as shown in the
above figure.
Eg – store a word “JOHNSENA” in memory starting from word 1000, using Big Endian
and Little endian.
Bigendian -
1000 J O H N
1000 1001 1002 1003
1004 S E N A
1004 1005 1006 1007
Little endian -
1000 J O H N
1003 1002 1001 1000
1004 S E N A
1007 1006 1005 1004
WORD ALLIGNMENT
16 bit
Word size 32 bit
64 bit
The structure of memory for 16 bit CPU, 32 bit CPU and 64 bit CPU are as shown in the figures
1,2 and 3 respectively
It is process of assignment of addresses of two successive words and this address is the number of
bytes in the word is called as Word alignment.
The character occupies 1 byte of memory and hence byte address for memory.
The numbers occupies 2 bytes of memory and hence word address for numbers.
6. MEMORY OPERATION
Both program instructions and operands are in memory. To execute each instruction has
to be read from memory and after execution the results must be written to memory. There
are two types of memory operations namely 1. Memory read and 2. Memory write
Memory read operation [ Load/ Read / Fetch ]
Memory write operation [ Store/ write ]
32 bits
(1) The processor loads MAR (Memory Address Register) with the address of the memory
location.
(2) The Control unit of processor issues memory read control signal to enable the memory
component for read operation.
(3) The processor reads the data from memory into the Accumulator by means of bi-directional
data bus.
It is the process of transferring the 1 word of data from Accumulator into the Memory.
The Memory write operation can be implemented by means of STORE instruction.
The STORE instruction transfers 1 word of data from Accumulator into the Memory
location as shown in the fig.
Accumulator
5000
5004
32 bits 5008
5012
5016
5020
32 bits
Steps for Memory Write Operation
The processor loads MAR with the address of the Memory location.
The Control Unit issues the Memory Write control signal.
The processor transfers 1 word of data from the Accumulator into the Memory location
by means of bi-directional data bus.
2. ALU Operations
The instructions are designed to perform arithmetic operations such as Addition, Subtraction,
Multiplication and Division as well as logical operations such as AND, OR and NOT operations.
Ex1: ADD R0, R1
The mathematical representation of this instruction is as follows:
R1← [R0] + [R1]; Adds the content of R0 with the content of R1 and result is placed in R1.
Ex2: SUB R0, R1
The mathematical representation of this instruction is as follows:
R1← [R0] - [R1] ; Subtracts the content of R0 from the content of R1 and result is placed
in R1.
EX3: AND R0, R1 ; It Logically multiplies the content of R0 with the content of R1 and result is
stored in R1. (R1= R0 AND R1)
Ex4: NOT R0 ; It performs the function of complementation.
3. I/O Operations: The instructions are designed to perform INPUT and OUTPUT
operations. The processor uses MOV instruction to perform I/O operations.
The input Device consists of one temporary register called as DATAIN register and output register
consists of one temporary register called as DATAOUT register.
a) Input Operation: It is a process of transferring one WORD of data from DATA IN
register to processor register.
Ex: MOV DATAIN, R0
The mathematical representation of this instruction is as follows,
R0← [DATAIN]
b) Output Operation: It is a process of transferring one WORD of data from processor
register to DATAOUT register.
Ex: MOV R0, DATAOUT
The mathematical representation of this instruction is as follows,
[R0]→ DATAOUT
ADD R0 , R1 , R2
Opcode source1, Source2, Destination
This instruction adds the contents of R0 with the contents of R1 and result is stored in R2.
The mathematical representation of this statement is given by
R2 ←[R0] + [R1].
Such a notations are called as “Assembly Language Notations”
Consider the arithmetic expression Z = A + B, Where A,B,Z are the Memory locations.
Steps for evaluation
1. Access the first memory operand whose symbolic name is given by A.
2. Access the second memory operand whose symbolic name is given by B.
3. Perform the addition operation between two memory operands.
4. Store the result into the 3rd memory location Z.
5. The mathematical representation is Z ←[A] + [B].
opcode operand
Ex1: LOAD B
This instruction copies the contents of memory location whose symbolic name is given
by „B‟ into the Accumulator as shown in the figure.
The mathematical representation of this instruction is as follows
ACC ← [B]
Accumulator Memory
Ex2: STORE B
This instruction copies the contents of Accumulator into memory location whose
symbolic name is given by „B‟ as shown in the figure. The mathematical representation is as
follows
B ← [ACC].
Memory
Accumulator
Ex3: ADD B
This instruction adds the contents of Accumulator with the contents of Memory
location „B‟ and result is stored in Accumulator.
The mathematical representation of this instruction is as follows
ACC ←[ACC]+ [B]
The system bus consists of uni-directional address bus,bi-directional data bus and control bus
“It is the process of accessing the 1st instruction from memory whose address is stored in program
counter into Instruction Register (IR) by means of bi-directional data bus and at the same time
after instruction access the contents of PC are incremented by 4 in order to access the next
instruction. Such a process is called as “Straight Line Sequencing”.
INSTRUCTION EXECUTION
There are 4 steps for instruction execution
1 Fetch the instruction from memory into the Instruction Register (IR) whose address
is stored in PC.
IR ← [ [PC] ]
2 Decode the instruction.
3 Perform the operation according to the opcode of an instruction
4 Load the result into the destination.
5 During this process, Increment the contents of PC to point to next instruction ( In
32 bit machine increment by 4 address)
PC ← [PC] + 4.
6 The next instruction is fetched, from the address pointed by PC.
BRANCHING
Suppose a list of „N‟ numbers have to be added. Instead of adding one after the other, the
add statement can be put in a loop. The loop is a straight-line of instructions executed as many
times as needed.
The „N‟ value is copied to R1 and R1 is decremented by 1 each time in loop. In the loop find the
value of next elemet and add it with Ro.
In conditional branch instruction, the loop continues by coming out of sequence only if
the condition is true. Here the PC value is set to „LLOP‟ if the condition is true.
The PC value is set to LOOP, if the previous statement value is >0 ie. after decrementing R1 value
is greater than 0.
If R1 value is not greater than 0, the PC value is incremented in a mormal sequential way and the
next instruction is executed.
C V Z N
1 N (NEGATIVE) Flag:
It is designed to differentiate between positive and negative result.
It is set 1 if the result is negative, and set to 0 if result is positive.
2 Z (ZERO) Flag:
It is set to 1 when the result of an ALU operation is found to zero, otherwise it is cleared.
3 V (OVER FLOW) Flag:
In case of 2s Complement number system n-bit number is capable of representing a
range of numbers and is given by -2n-1 to +2n-1. . The Over-Flow flag is set to 1 if the result
is found to be out of this range.
4 C (CARRY) Flag :
This flag is set to 1 if there is a carry from addition or borrow from subtraction,
otherwise it is cleared.
8. Addressing Modes
The various formats of representing operand in an instruction or location of an operand is called
as “Addressing Mode”. The different types of Addressing Modes are
a) Register Addressing
b) Direct Addressing
c) Immediate Addressing
d) Indirect Addressing
e) Index Addressing
f) Relative Addressing
g) Auto Increment Addressing
h) Auto Decrement Addressing
a. REGISTER ADDRESSING:
In this mode operands are stored in the registers of CPU. The name of the register is directly
specified in the instruction.
Ex: MOVE R1,R2 Where R1 and R2 are the Source and Destination registers respectively. This
instruction transfers 32 bits of data from R1 register
into R2 register. This instruction does not refer
memory for operands. The operands are directly
available in the registers.
b. DIRECT ADDRESSING
It is also called as Absolute Addressing Mode. In this addressing mode operands are stored in the
memory locations. The name of the memory location is directly specified in the instruction.
Ex: MOVE LOCA, R1 : Where LOCA is the memory location and R1 is the Register.
This instruction transfers 32 bits of data from memory location X into the General Purpose
Register R1.
c. IMMEDIATE ADDRESSING
In this Addressing Mode operands are directly specified in the instruction. The source field is used
to represent the operands. The operands are represented by # (hash) sign.
d. INDIRECT ADDRESSING
In this Addressing Mode effective address of an operand is stored in the memory location or
General Purpose Register.
This instruction adds the data from the memory location whose address is stored in R1 with the
contents of R0 Register and the result is stored in R0 register as shown in the fig.
This instruction adds the data from the memory location whose address is stored in „X‟
memory location with the contents of R0 and result is stored in R0 register.
Note : Offset : It is the difference between the starting effective address of the memory location
and the effective address of the operand fetched from memory.
This instruction adds the contents of memory location whose EA is the sum of contents of R1
with 20 and with the contents of R2 and result is placed in R2 register. The diagrammatic
representation of this mode is as shown in the fig.
This instruction adds the data from the memory location whose address is given by [1000 +
[R1] with the contents of R2 and result is placed in R2 register.
The symbolic representation of this mode is X (PC).Where X is the offset value and PC is the
Program Counter to store the address of the next instruction to be executed.
It can be represented as
EA of an operand = X + (PC).
This Addressing Mode is useful to calculate the EA of the target memory location.
In this Addressing Mode , EA of an operand is stored in the one of the GPR s of the CPU. This
Addressing Mode increment the contents of memory register by 4 memory locations after operand
access.
The symbolic representation is
(RI)+ Where Ri is the one of the GPR.
Ex: MOVE (R1)+ , R2
This instruction transfer‟s data from the memory location whose address is stored in R1 into R3
register and then it increments the contents of R1 by 4 memory locations.
In this Addressing Mode , EA of an operand is stored in the one of the GPR s of the CPU. This
Addressing Mode decrements the contents of memory register by 4 memory locations and then
transfers the data to destination.