COA Unit3 Notes
COA Unit3 Notes
COA Unit3 Notes
Instruction Representation
Within the computer, each instruction is represented by a sequence of bits. The instruction is
divided into fields,corresponding to the constituent elements of the instruction. The instruction
format is highly machine specific and it mainly depends on the machine architecture. A simple
example of an instruction format is shown in the figure. It is assume that it is a 16-bit CPU. 4 bits
are used to provide the operation code. So, we may have to 16 (24 = 16)
Opcodes are represented by abbreviations, called mnemonics, that indicate the operations.
Common examples include:
ADD Add
SUB Subtract
MUL Multiply
DIV Division
LOAD Load data from memory to CPU
STORE Store data to memory from CPU.
Operation : How many and which operations to provide, and how complex operations
should be.
Data Types : The various type of data upon which operations are performed.
Instruction format : Instruction length (in bits), number of addresses, size of various fields and
so on.
Registers : Number of CPU registers that can be referenced by instructions and their
use.
Addressing : The mode or modes by which the address of an operand is specified.
Types of Operands
Machine instructions operate on data. Data can be categorised as follows :
Addresses: It basically indicates the address of a memory location. Addresses are nothing but
the unsigned integer, but treated in a special way to indicate the address of a memory location.
Address arithmatic is somewhat different from normal arithmatic and it is related to machine
architecture.
Numbers: All machine languages include numeric data types. Numeric data are classified into
two broad categories:
integer or fixed point and floating point.
Characters: A common form of data is text or character strings. Since computer works with bits,
so characters are represented by a sequence of bits. The most commonly used coding scheme
is ASCII (American Standard Code for
Information Interchange) code.
Logical Data: Normally each word or other addressable unit (byte, halfword, and so on) is
treated as a single unit of data. It is sometime useful to consider an n-bit unit as consisting of n
1-bit items of data, each item having the value 0
or 1. When data are viewed this way, they are considered to be logical data. Generally 1 is
treated as true and 0 is
treated as false.
Types of Opearations
The number of different opcodes and their types varies widely from machine to machine.
However, some general type of operations are found in most of the machine architecture. Those
operations can be categorized as follows:
n Data Transfer
n Arithmatic
n Logical
n Input Output [ I/O ]
n System Control
n Transfer
Data Transfer:
The most fundamental type of machine instruction is the data transfer instruction. The data
transfer instruction must specify several things. First, the location of the source and destination
operands must be specified. Each location could be memory, a register, or the top of the stack.
Second, the length of data to be transferred must be indicated. Third, as with all instructions
with operands, the mode of addressing for each operand must be specified.
The CPU has to perform several task to accomplish a data transfer operation. If both source
and destination are registers, then the CPU simply causes data to be transferred from one
register to another; this is an operation internal to the CPU.
If one or both operands are in memory, then the CPU must perform some or all of the following
actions:
a) Calculate the memory address, based on the addressing mode.
b) If the address refers to virtual memory, translate from virtual to actual memory address.
c) Determine whether the addressed item is in cache.
d) If not, issue a command to the memory module.
Arithmatic:
Most machines provide the basic arithmatic operations like add, subtract, multiply, divide etc.
ALU input and to deliver the result of the ALU operation.
Input/Output :
Input/Output instructions are used to transfer data between input/output devices and
memory/CPU register. Commonly available I/O operations are:
Operation Name Description
Input (Read) Transfer data from specified I/O port or device to destination
(e.g., main memory or processor register)
Output (Write) Transfer data from specified source to I/O port or device.
Start I/O Transfer instructions to I/O processor to initiate I/O
operation.
Test I/O Transfer status information from I/O system to specified destination
Branch Instruction
A branch instruction, also called a jump instruction, has one of its operands as the address of
the next instruction to be executed. Basically there are two types of branch instructions:
Conditional Branch instruction and unconditionla branch instruction. In case of unconditional
branch instruction, the branch is made by updating the program counter to address specified in
operand. In case of conditional branch instruction, the branch is made only if a certain condition
is met. Otherwise, the next instruction in sequence is executed.
There are two common ways of generating the condition to be tested in a conditional branch
instruction
First most machines provide a 1-bit or multiple-bit condition code that is set as the result of
some operations. As an example, an arithmetic operation could set a 2-bit condition code with
one of the following four values: zero, positive,negative and overflow. On such a machine, there
could be four different conditional branch instructions:
BRP X Branch to location X if result is positive
BRN X Branch to location X if result is negative
BRZ X Branch to location X is result is zero
BRO X Branch to location X if overflow occurs
In all of these cases, the result referred to is the result of the most recent operation that set the
condition code.
A instruction is of various length depending upon the number of addresses it contain. Generally
CPU organization are of three types on the basis of number of address fields:
In first organization operation is done involving a special register called accumulator. In second
on multiple registers are used for the computation purpose. In third organization the work on
stack basis operation due to which it does not contain any address field. It is not necessary that
only a single organization is applied a blend of various organization is mostly what we see
generally.
A stack based computer do not use address field in instruction.To evaluate a expression
first it is converted to revere Polish Notation i.e. Post fix Notation.
Expression: X = (A+B)*(C+D)
Postfixed : X = AB+CD+*
TOP means top of stack
M[X] is any memory location
A TOP = A
PUSH
PUSH B TOP = B
ADD TOP = A+B
PUSH C TOP = C
PUSH D TOP = D
ADD TOP = C+D
MUL TOP = (C+D)*(A+B)
POP X M[X] = TOP
Expression: X = (A+B)*(C+D)
AC is accumulator
M[] is any memory location
M[T] is temporary location
LOAD A AC = M[A]
ADD B AC = AC + M[B]
STORE T M[T] = AC
LOAD C AC = M[C]
ADD D AC = AC + M[D]
MUL T AC = AC * M[T]
STORE X M[X] = AC
Expression: X = (A+B)*(C+D)
R1, R2 are registers
M[] is any memory location
Instruction Cycle
A program residing in the memory unit of a Computer consists of a sequence of
instructions. These instructions are executed by the processor by going through a cycle
for each instruction.
Program Control
Branch Instruction: The program counter is changed to the new (branch destination) location.
Call Subroutine: The program counter is pushed onto the stack, and the program counter is then is changed to
Examples:
Example 1: The Main program calls a subroutine. The return address is stored in a register.
Example 1: The Main program calls a subroutine. The return address is stored in a register.
Example 1: The Main program calls a subroutine. The return address is stored in a register.
Three major issues in subroutine calls:
● Linkage
Two things need to be done when jumping from the invoking routine, say MAIN, to the
invoked routine, say SUB:
● Parameter/Result Passing
(1) Pass parameters (variables) to be used in the function or their addresses from
MAIN to SUB.
● Data Protection
If function SUB need some CPU registers whose contents will be used by MAIN again
after SUB is executed, these registers need to be saved somewhere before SUB and then
restored after SUB. The most suitable place to save them is a stack in MM, where both
the return addresses and the contents of registers used by previous routines are stored to
accommodate both nested and recursive function calls.
RISC chips require fewer transistors which make them cheaper to design and produce. In RISC,
the instruction set contains simple and basic instructions from which more complex instruction
can be produced. Most instructions complete in one cycle, which allows the processor to handle
many instructions at same time.
In this instructions are register based and data transfer takes place from register to register.
Characteristic of RISC –
CISC Processor
Instruction size and Large set of instructions with variable formats Small set of instructions with
format (16-64 bits per instruction). fixed format (32 bit).
Most micro coded using control memory (ROM) Mostly hardwired without
CPU control
but modern CISC use hardwired control. control memory.
Sometimes called CP, the Clock pulse is located inside a computer and is used to synchronize the timing of
hardware components. The speed of the computer's processor, measured in MHz or GHz, refers to its number
of clock pulse cycles per second. Every microprocessor has an internal clock that regulates the speed at
which it executes instructions and also synchronizes it with other components. The speed at which
the microprocessor executes instructions is called clock speed.
What is Pipelining?
Pipelining is the process of accumulating instruction from the processor through a pipeline. It
allows storing and executing instructions in an orderly process. It is also known as pipeline
processing.
Pipelining is a technique where multiple instructions are overlapped during execution. Pipeline is
divided into stages and these stages are connected with one another to form a pipe like structure.
Instructions enter from one end and exit from another end.
In digital computers, an interrupt is a response by the processor to an event that needs attention from the
software. An interrupt condition alerts the processor and serves as a request for the processor to interrupt
the currently executing code when permitted, so that the event can be processed in a timely manner.
An interrupt is a signal sent to the processor that interrupts the current process. ... For example, if you are
using a word processor and press a key, the program must process the input immediately.
Types of Pipeline
1. Arithmetic Pipeline
2. Instruction Pipeline
Arithmetic Pipeline
Arithmetic pipelines are usually found in most of the computers. They are used for floating point
operations, multiplication of fixed point numbers etc. For example: The input to the Floating
Point Adder pipeline is:
X=A*2a
X=B*2b
Here A and B are mantissas (significant digit of floating point numbers), while a and b are
exponents.
Registers are used for storing the intermediate results between the above operations.
Instruction Pipeline
In this a stream of instructions can be executed by overlapping fetch, decode and execute phases
of an instruction cycle. This type of technique is used to increase the throughput of the
computer system.
An instruction pipeline reads instruction from the memory while previous instructions are being
executed in other segments of the pipeline. Thus we can execute multiple instructions
simultaneously. The pipeline will be more efficient if the instruction cycle is divided into
segments of equal duration
Advantages of Pipelining
Disadvantages of Pipelining
To execute an instruction, there are two types of control units Hardwired Control unit and Micro-
programmed control unit.
. Control
Sequence Counter Combinational . signals
Logic Circuits
• Microprogrammed
C
Memory A
R
:
C
o
n
t
r
o
l
A
d
d
r
e
s
s
R
e
g
i
s
t
e
r
C
D
R
:
C
o
n
t
r
o
l
D
a
t
a
R
e
g
i
s
t
e
Instruction code r
Next Address .
Control Decoding . Control
Generator CA CDR
Memory Circuit signals
(sequencer) R
3
Microprogrammed Control Unit
• Control memory
– Memory contains control words
• Microinstructions
– Control words stored in control memory
– Specify control signals for execution of
microoperations
• Microprogram
– Sequence of microinstructions
Control Memory
• Read-only memory (ROM)
• Content of word in ROM at given address specifies
microinstruction
• Each computer instruction initiates series of
microinstructions (microprogram) in control memory
• These microinstructions generate microoperations to
– Fetch instruction from main memory
– Evaluate effective address
– Execute operation specified by instruction
– Return control to fetch phase for next instruction
Address C
o
n
t
r
o
l
w
o
r
d
(
m
i
c
Control
memory
r (ROM) u
o c
i t
n i
s o
t n
r )
C
o
n
t
r
o
l
O
r
g
a
n
i
z
a
t n
i Next Address
Generator CA
Control
Memory CDR
Control
word
o (sequencer) R (ROM)
• Control memory
– Contains microprograms (set of microinstructions)
– Microinstruction contains
• Bits initiate microoperations
• Bits determine address of next microinstruction
• Control address register (CAR)
– Specifies address of next microinstruction
6
Microprogram Routines
• Subroutine
– Sequence of microinstructions used by other routines
to accomplish particular task
• Example
– Subroutine to generate effective address of
operand for memory reference instruction
• Subroutine register (SBR)
– Stores return address during subroutine call
Mapping of Instruction
• Each computer instruction has its own
microprogram routine stored in a
given location of the control memory
• Mapping
– Transformation from instruction code bits to
address in control memory where routine is
located
12
Mapping of Instruction
• Example
– Mapping 4-bit operation code to 7-bit address
OP-codes of Instructions
ADD AND 0000
LDA 0001
0010
C
o
n
t
r
o
l
m
e
m
o
r
y
Mapping bits 0 xxxx 00 Address
ADD Routine
0 0000 00
0 0001 00
AND Routine
0 0010 00
LDA Routine
13
Address Sequencing
• Address sequencing capabilities
required in control unit
– Incrementing CAR
– Unconditional or conditional branch,
depending on status bit conditions
– Mapping from bits of instruction to address for
control memory
– Facility for subroutine call and return
25