Instruction Set Arch
Instruction Set Arch
Lesson Structure
5.0 Objective
5.1 Introduction
5.7 Summary
5.0 Objectives
After going through this unit we should be able to:
define instruction set and the characteristics of instruction set;
describe the element of an instruction and differentiate various types of
operands;
distinguish between types of instructions and operations performed by the
instructions;
differentiate types of instructions set on the basis of addresses in instruction
sets;
identity various addressing schemes and discuss instruction format design
issues.
5.1 Introduction
The internal organization of a digital system is defined by the registers it
employs and the sequence of micro-operations it performs on data stated in the
registers. A digital computer is a general purpose digital system capable of executing
various operations and in addition can be instructed as to what specific sequence of
operations it must perform . The user of a computer can control the process by
[ 112 ]
Instruction Set Architecture
means of programs that is a set of instruction that specify the operations, operands
and the sequence in which processing has to occur.
The Instruction Set Architecture (ISA) is the part of the processor that is
visible to the programmer or compiler designer. They are the parts of a processor
design that need to be understood in order to write assembly language, such as the
machine language instructions and registers. The ISA serves as the boundary
between software and hardware.
In this unit we will define instruction, types of instructions, various addressing
schemes and their importance. In addition, we will also discuss the design issues
relating to instruction format.
[ 113 ]
Instruction Set Architecture
a computer are machine dependent, that is, a different processors have different
instruction sets. However, a newer processor that may belong to some family may
have a compatible but extended instruction set of an old processor of that family.
Instructions can have different formats. the instruction format includes the following
components:
the instruction length;
the type;
length and position of operation codes in an instruction; and
the number and length of operand addresses etc.
Each instructions consists of several fields. The most common fields found in
instruction formats are:
Opcode : It specifies the operation (ADD, SUBTRACT, MULTIPLY, etc.) to be
performed.
Operands : An address field of operand on which data processing is to be
performed.
An operand can reside in the memory or a processor register or can be
incorporated within the operand field of instructions as an immediate
constant. Therefore a mode field is needed that specifies the way the
operand or its address is to be determined.
A sample instruction format is given in figure 1.
0 56 7 8 31
Instruction Length
Figure 1 : An Instruction Format of 32 bits
From the above figure we have the following observations :
(i) The size of the opcode is 6 bits. So we will have 26 = 32 operations.
(ii) There is only one operand address machine.
(iii) There are two bits for addressing modes. Therefore , there are 22 = 4 different
addressing modes possible for this machine.
(iv) The last field (8 - 31 bits = 24 bits) here is the operand or the address of
operand field.
In case of immediate operand the maximum size of the unsigned operand
would be 224. In case it is an address of operand in memory, then the maximum
physical memory size supported by this machine is 224 = 16 MB.
[ 114 ]
Instruction Set Architecture
[ 115 ]
Instruction Set Architecture
INC A X AX AX + 1
DEC CX CX CX –1 (decrement CX content by 1)
POP BX POP BX from the stack
The above instructions operate n the single operand specified in the
instruction.
Two Operands Instruction
The instruction in which two operands are explicitly specified are known as
two operands or address instructions.
[ 117 ]
Instruction Set Architecture
Examples
[ 118 ]
Instruction Set Architecture
Register to memory.
Register to I/O part and vice versa.
These instruction have the following properties.
Two operands, the source and destination
They must be of the same data-type that is either of type byte or type word.
Both the source and destination control refer to memory locations in the same
instructions.
The source can be register or a memory location or an immediate data.
The destination can be register or a memory location.
These instructions do not effect the CPU flags.
The instruction also need the mode of addressing for each operand. A table is
given below, which lists some data transfer instructions with their mnemonic
symbols. Different computers may use different mnemonics for the same instruction.
Some arithmetic operation their mnemonics and description are given below in
the table.
Arithmetic operations Mnemonics Description
Addition ADD Adds two operands and stores the result.
Subtraction SUB Subtracts source from destination.
Decrement DEC Subtract one from destination.
Compare CMP Compare source with destination and flags
are set to indicate carry.
Multiply MUL Multiplies source to destination.
Divide DIV Divide accumulator by unsigned value
stored in reg/men.
Logical Instruction: AND, OR, NOT, XOR are same logical instructions that
operates on binary data stored in register. Logical shift (Left shift or Right shift) is
also used for transfer of bits either to the left or to the right.
Example:
(i) AND AX, FOOOH, if AX = FFOOH
then AX = FFOO & FOOO
= FOOOH
(ii) R1 = 1101 1001
R2 = 0010 1110
R x or R2 = 1111 0111
Shift Operation : It is basically of three types :
(i) Logical shift : Insets zero to the end of bit position and the other bits
of a word are shifted left or right respectively.
(ii) Arithmetic shift: On the arithmetic shift right, the sign bit is
replicated into the bit position to its right. On an arithmetic shift left, a
logical shift left is performed on all bits but the sign bit, which is
retained.
(iii) Circular shift: Rotate left or rotate right. Bits are shifted out at one
end of the word are not lost as in a logical shift but are calculated back
into the other end.
Branch Instructions
The branch instructions transfers control from the normal sequence of
instruction execution to the specified destination or target instruction. These
instructions are broadly categorized as,
(i) Conditional branch and
(ii) Unconditional branch.
[ 120 ]
Instruction Set Architecture
[ 122 ]
Instruction Set Architecture
[ 123 ]
Instruction Set Architecture
[ 124 ]
Instruction Set Architecture
Early machines used stack or accumulator architectures but in the last 15 year
all CPUs are made up of GPR processors. The three major reasons are:
(i) that register are faster than memory;
(ii) the more data that can be kept internally in the CPU the faster the
program will run.
(iii) that register are easier for a compiler to use.
But while CPU’s with GPR were clearly better than previous stack and
accumulator based CPU’s yet they were lacking in several areas being: Instructions
were of varying length from 1 bye to 6-8 bytes. This causes problems with the pre-
fetching and pipelining of instructions. ALU instructions could have operands that
were memory locations because the time to access memory is slower and so does
the whole instruction.
Thus in the early 1980 the idea of RISC was introduced. RISC stand for
reduced instruction set computer. Unlike CISC, this ISA uses fewer instructions with
simple constructs so they can be executed much faster within the CPU without
having to use memory as often. The first RISC CPU, the MIPS 2000, has 32 GPRs.
MIPS is a load/store architecture, which means that only load and store instructions
access memory. All other computational instructions operate only on values stored in
stored registers.
[ 125 ]
Instruction Set Architecture
Addressing Mode
Displacement
[ 126 ]
Instruction Set Architecture
[ 127 ]
Instruction Set Architecture
Instructions Register
Opcode Register Data
[ 128 ]
Instruction Set Architecture
Displacement
Element 1
Element 0
Figure 10 : Indexed Addressing
[ 129 ]
Instruction Set Architecture
Memory
Displacement Element n
Element n – 1
+
Base Register
Element 1
Element 0
Figure 11 : Base Addressing
5.4.1.9 Register Relative Mode
In this mode the effective address (EA) is generated by adding the content of
the base register or index register to an 8-bit or a 16-bit displacement value that is,
EA = (BX) + disp
(BP) + disp
(SI) + displ
(DI) + displ
Examples
(1) A [BX]
(2) [BX + 20]
The process of register relative mode can be shown as follows :
[ 130 ]
Instruction Set Architecture
Register Memory
EA
Index + Data
Register
Base address
[ 131 ]
Instruction Set Architecture
pushed. A stack provides a sort-of indirect addressing and indexed addressing. This
is not a very common addressing scheme. The operand is found on the top of a
stack. In some machines the top two elements of stack and top of stack pointer is
kept in the CPU registers, while the rest of the elements may reside in the memory.
Figure 14 shows the stack addressing schemes.
Main Memory
Instruction
Factors Descriptions
Memory size If larger memory range is to be addressed,
then more bits may be required in address
field.
[ 133 ]
Instruction Set Architecture
[ 134 ]
Instruction Set Architecture
The MIPS CPU has a five-stage CPU pipeline to execute multiple instructions at
the same time. It defines the 5 steps of execution of instructions that may be
performed in an overlapped fashion. The figure below show the pipelining concept :
Instruction 3 1 2 3 4 5
Figure 15 : Pipeline
From the above figure we have that :
All the stages are independent and distinct, that is, the second stage execution
of Instruction should not hinder Instruction 2.
The overall efficiency of the system becomes better.
The early MIPS architectures had 32-bit instructions and later versions have
64-bit implementations.
The first commercial MIPS CPU model, the R2000, whose instruction format is
discussed below, has thirty-two 32-bit registers and its instructions are 32 bit long.
R Format
Converting an R mnemonic into the equivalent binary machine code is
performed in the following way :
31 0
31 26,25 11,10 65 0
Shift (shamt)–Used with the shift and rotate instructions, this is the amount
by which the source operand rs is rotate/shifted. This field is 5 bit long (6to 10).
Funct–For instructions that share an opcode, the funct parameter contains
the necessary control codes to differentiate the different instructions. 6 bits long (0
to 5). Example : Opcode 0 × 00 accesses the ALU, and the funct selects which ALU
function to use.
I Format
I instructions are used when the instruction must operate on an immediate
value and a register value. Immediate values may be a maximum of 16 bits long.
Larger numbers may not be manipulated by immediate instructions. I instruction are
converted into machine code words in the following format.
31 0
Opcode rs rt IMM
31 2625 1615 0
Opcode–The 6 bit opcode of the instruction. In I instructions, all mneumonics
have a one-to-one correspondence with the underlying opcodes. This is because
there is no funct parameter to differentiate instructions with an identical opcode. 6
bits (26 to 31)
rs, rt– The source and destination register operands, respectively. 5 bits each
(21 to 25 and 16 to 20, respectively).
IMM– The 16 bit immediate value. 16 bits (0 to 15). This value is usually used
as the offset value in various instructions, and depending on the instruction, may be
expressed in two’s complement.
J Format
J instructions are used when a jump needs to be performed. The J instruction
has the most space for an immediate value, because addresses are large number. J
instructions have the following machine-code format :
31 0
Opcode Address
31 2625 0
Opcode-The 6 bit opcode corresponding to the particular jump command. (26
to 31).
Address-A 26-bit address of the destination. (0 to 25).
[ 137 ]
Instruction Set Architecture
All MIPS instructions are of the same length, requiring different kinds of
instruction formats for different types of instructions.
MIPS uses various addressing modes :
1. Register and Immediate addressing modes for operations.
2. Immediate and Displacement addressing for Load and Store
instructions.
(In displacement addressing, the operand is at the memory location whose address
is the sum of a register).
5.7 Summary
In this unit we have explained Instruction Set Architecture (ISA), its
characteristics, design confederation etc. We also discussed different types of (ISA),
types of instructions and the operation performed by them. Various addressing schemes
have also been discussed with examples. An example of instruction format has also
been provided to make the concept more clear.
5.8 Questions
1. What is an Instruction ? What are the elements of an instruction ?
2. Explain in brief the design considerations of an instruction set.
3. What are different operand Data Types ?
4. Explain General Purpose Register (GPR).
5. What is addressing scheme ? Why it is required ?
6. Describe different types of addressing schemes.
7. What are the factors that must be considered for deciding the instruction length ?
8. Explain some factors considered for selection of addressing bits.
9. What are the advantages of variable length instruction ?
10. Give and describe an example of an instruction format.
[ 138 ]