INSTRUCTION SET - Unit-1
INSTRUCTION SET - Unit-1
ARCHITECTURE
St~wcture Page N9.
Introduction
Objectives
Instruction Set Characteristics
Instruction Set Design Considerations
1.3.1 Operand Data Types
1.3.2 Types of Instructions
1.3.3 Number of Addresses in an Instruction
Addressing Schemes
1.4.1 Immediate ~ddressin~
1.4.2 Direct Addressing
1.4.3 Indirect Addressing
1.4.4 Register Addressing
1.4.5 Register Indirect Addressing
1.4.6 Indexed Addressing Scheme
1.4.7 Base Register Addressing
1.4.8 Relative Addressing Scheme
1.4.9 Stack Addressing
Instruction Set and Format Design Issues
1.5.1 Instruction Length
1.5.2 A!location of Bits Among Opcode and Operand
1.5.3 2 Variable Length of Instructions
Example of Instruction Format
Summary
Solutions! Answers
1.O INTRODUCTION
The Instruction Set Architecture (ISA) is the part of the processor that is visible to the
pt ogramrner 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
i instructions and registers. Parts of the architecture that are left to the implementation
ate not part of ISA. The ISA serves as the boundary between software and hardware.
The term instruction will be used in this unit more often. What is an instruction?
What are its components? What are different types of instructions? What are the
various addressing schemes and their importance? This unit is an attempt to answer
these questions. In addition, the unit also discusses the design issues relating to
ir~structionformat. We have presented here the instruction set of MIPS
(~ulicroprocessorwithout Interlocked Pipeline Stages) processor (very briefly) as an
e rample.
Clther related microprocessors instruction set can be studied from fiuther readings. We
will also discuss about the complete instruction set of 8086 micro-processor in unit 1,
Eilock 4 of this course.
OBJECTIVES
-1.1 /
After going through this unit you should be able to:
describe the characteristics of instruction set;
i
ious elements of an instruction;
differentiate various types of operands;
5
I
The Central
Processing Unit
distinguish various types of instructions and various operations performed by the
instructions;
identify different types of ISAs on the basis of addresses in instruction sets;
identify various addressing schemes; and
discuss the instruction format design issues.
The key role of the Central Processing Unit (CPU) is to perform the calculations, to
issue the commands, to coordinate all other hardware components, and executing
programs including operating system, application programs etc. on your computer.
But CPU is primarily the core hardware component; you must speak to it in the core
binary machine language. The words of a machine language are known as
instructions, and its syntax is known as an instruction set.
The common goal of computer designers is to build the hardware for implementing
the machine's instructions for CPU. From the programmer's point of view, the user
must understand machine or assembly language for low-level programming.
Moreover, the user must be aware of the register set, instruction types and the function
that each instruction performs.
This unit covers both the viewpoints. However, our prime focus is the programmer's
viewpoint with the design of instruction set. Now, let us define the instructions, parts
of instruction and so on.
Thils, each instruction consists of several fields. The most common fields found in
instruction formats are:
Optcode: (What operation to perform?)
I - 1
L
Opcode ( Addressing Mode
I
I
I
Instruction Length-
Operand or address of operand
-
Figure 1: A Hypothetical Instruction Format of 32 bits
b
I
I
/
t
1
Please note the following points in Figure I:
The opcode size is 6 bits. So, in general it will have 26 = 32 operations.
(However, when you will study more architectures fiom further readings, you
will find even through these bits using special combinations. Instruction set
i designers have developed much more operations),
I
t
a There is only one operand address machine. What is the significance of this? You
I
will find an answer of this question in section 1.3.3 of this unit.
There are two bits for addressing modes. Therefore, there are 22 = 4 different
addressing modes possible for this machine.
a The last ield (8 - 3 1 bits = 24 bits) here is the operand or the address of operand
field.
111 case of immediate operand the maximum size of the unsigned operand would be
224.
The opcode field of an instruction is a group of bits that define various processor
operations such as LOAD, STORE, ADD, and SHIFT to be performed on some data
r
stored in registers or memory.
The operand address field can be data, or can refer to data - that is address of data, or
can be labels, which may be the address of an instruction you want to execute next,
such labels are commonly used in Subroutine call instructions. An operand address
can be:
The memory address
.
CPU register address
I/0 device address
However, later it was found in the studies of program style that many complex
instructions found CISC are not used by the program. This lead to the idea of making
a simple but faster computer, which could execute simple instructions much faster.
These computers have simple instructions, registers addressing and move registers.
These are called Reduced Instruction Set Computers (RISC). We will study more
about RISC in Unit 5 of this Block.
3. The opcode field of an instruction specifies the address field of operand on which
data processing is to be performed.
i 4. The operands placed in processor registers are fetched faster than that of
operands placed in memory.
Instruction Set
Architecture
CONSIDERATIONS
-
Some of the basic considerations for instruction set design include selection of:
A set of data types (e.g. integers, long integers, doubles, character strings etc.).
A set of operations on those data types. '
~3 Addresses Characters
EBCDIC etc.)
Logical
Data (0 or 1
values only)
Numbers: A11 machine languages include numeric data types. Numeric data
usually use one of three representations:
Floating-point numbers-single precision (1 sign bit, 8 exponent bits, 23
mantissa bits) and double precision (1 sign bit, 11 exponent bits, 52 mantissa
bits).
The Central
Processing Unit
Binary Coded Decimal Numbers.
Logical data: Each word or byte is treated as a single unit of data. When an n-bit
data unit is considered as consisting of n 1-bit items of data with each item
having the value 0 or 1, then they are viewed as logical data. Such bit-oriented
data can be used to store an array of Boolean or binary data variables where each
variable can take on only the values 1 (true) and 0 (false). One simple application
of such a data may be the cases where we manipulate bits of a data item. For
example, in floating-point addition we need to shift mantissa bi,ts.
Types of Instructions
I
1,ogical: AND. OR, NOT, XOR operate on binary data stored in registers. For
example, if two registers contain the data:
ELI AND R2 = 101 1 0000. Thus, the AND operation can be used as a mask that selects
certain bits in a word and zeros out the remaining bits. With one register is set to all
1's, the XOR operation inverts those bits in R, register where R2 contains 1.
Shift: Shift operation is used for transfer of bits either to the left or to the right. It can
be used to realize simple arithmetic operation or data communication/recognitionetc,
Shift operation is of three types:
1. Logical shifts LOGICAL SHIFT LEFT and LOGICAL SHIFT RIGHT inserf
zeros to the end bit position and the other bits of a word are shifted left or right
respective!^. The end bit position is the leftmost bit for shift right and the
rightmost bit position for the shift left. The bit shifted out is lost.
The arithmetic left shift and a logical left shift when performed on numbers
represented in two's complement notation cause multiplication by 2 when there is
no overflow. Arithmetic shift right corresponds to a division by 2 provided there
is no underflow.
3. Circular shifts ROTATE LEFT and ROTATE RIGHT. Bits shifted out at one
end of the word are not lost as in a logical shift but are circulated back into
the other end.
These instructions specify conditions for altering the sequence of program execution
or in other words the content of PC (program counter) register. PC points to memory I
location that holds the next instruction to be executed. The change in value of-PC as a
result of execution of control instruction like BRANCH or JUMP causes a break in
I
the sequential execution of instructions. The most common control instructions are: 1
I
BRANCH and JUMP may be conditional or unconditional. JUMP is an
unconditional branch used to implement simple loops. JNE jump not equal is a
conditional branch instruction. The conditional branch instructions such as BRP X
and BRN X causes a branch to memory location X if the result of most recent
operation is positive or negative respectively. If the condition is true, PC is loaded
with the branch address X and the next instruction is taken from X, otherwise, PC is
not altered and the next instruction is taken from the location pointed by PC. Figure 5
shows an unconditional branch instruction, and a conditional branch instruction if the
content of AC is zero.
OFFF
1000
1001 - . .
1002 i
1" Cycle:
1001 (with location X = 2001 which is value 10) 3 1002 3 1003 3
1 0 0 4 31005 (X is incremented to 2002)3 1006
2'd Cycle
The SKIP instruction is a zero-address instruction and skips the next instruction
to be executed in sequence. In other words, it increments the value of PC by one
instruction length. The SKIP can also be conditional. For example, the instruction
ISZ skips the next instruction only if the result of the most recent operation is
zero.
CALL and RETN are used for CALLing stibprograms and RETurning from
them. Assume that a memory stack has been built such that stack pointer points to
a non-empty location stack and expand towards zero address.
The Central
Processing Unit
CALL:
CALL X Procedure Call to function /procedure named X
CALL instruction causes the following to happen:
1. Decrement the stack pointer so that we will not overwrite last thing put on
stack, 4
(SP t SP- 1)
R o w orContml
102
103
zcr,
I-
20 1
202
Submutins
cliccution
I
3tr1
104
@) Flow of Control
(Init~al (procedure
state) call) return)
2. The contents of PC, which is pointing to NEXT instruction, the one just after the
CALL is pushed onto the stack, and, M [SP] +PC.
3. JMP to X, the address of the start of the subprogram is put in the PC register; this
is all a jump does. Thus, we go off to the subprogram, but we have to remember
where we were in the calling program, i.e. we must remember where we came
from, so that we can get back there again.
P C t X
Instruction Set
*RETN Return from procedure. Architecture
RETN instruction causes the following to happen:
1. Pops the stack, to yield an addressllabel; if correctly used, the top of the
stack will contain the address of the next instruction after the call from
which we are returning; it is this instruction with which we want to resume
in the calling program;
2. Jump to the popped address, i.e., put the address into the PC register.
PC f top of stack value; Increment SP.
Most computer instructions are divided into two categories, privileged and non-
privileged. A process running in privileged mode can execute all instructions from the
instruction set while a process running in user mode can only execute a sub-set of the
instructions. I10 instructions are one example of privileged instruction, clock
As far as operations and type of operands are concerned, we have already discussed
a b ~ uthese
t in the previous subsection. In this section let us look into some ofthe
architectures that are common in contemporary computer. But before we dlscuss the
architectures, let us look into some basic instruction set characteristics:
The operands can be addressed in memory, registers or VO device address.
Instructio~lhaving less number of operand addresses in an instruction may
require lesser bits in the instruction; however, it also restricts the range of
functionality that can be performed by the instructions. This implies that a CPU
instruction set having less number of addresses has longer programs, which
means longer instruction execution time. On the other hand, having more
, addresses may lead to more complex decoding and processing circuits.
Most of the instructions do not require more than three operand addresses.
Instructions having fewer addresses than three, use registers implicitly for
operand locations because using registers for operand references c m result in
smaller instructions as only few bits are needed for register addresses as against
memoj addresses.
The type of internal storage of operands in the CPU is the most basic
i
differentiation.
The Central
Processing Unit
The three most common types of ISAs are:
1. Evaluation Stack: The operands are implicitly on top of the stack.
2. Accumulator: One operand is implicitly the accumulator.
3. General Purpose Register (GPR): All operands are explicit, either registers or
memory locations.
PUSH A
PUSH B
ADD // operator POP operand(s) and PUSH result(s) (implicit on top of stack)
POP C
While most early machines used stack or accumulator architectures, in the last 15
years all CPUs made are GPR processors. The three major reasons are that registers
are faster than memory; the more data that can be kept internally in the CPU the faster
the program will run. The third reason is that registers are easier for a compiler to use.
13ut while CPU's with GPR were clearly better than previous stack and accumulator
based CPU's yet they were lacking in several areas. The areas being: Instructions
were of varying length from 1 byte to 6-8 bytes. This causes problems with the pre-
aching 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.
rhus in the early 1980s the idea of RISC was introduced. RISC stands 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
loadstore architecture, which means that only load and store instructions access
memory. All other computational instructions operate only on values stored in
registers.
The Central
Processing Unit Check Your Progress 2 I
!
I. Match the following pairs: I
But, why addressing schemes? The question of addressing is concerned with how '
operands are interpreted. In other words, the term 'addressing schemes' refers to the
mechanism employed for specifying operands. There are a multitude of addressing
schemes and instruction formats. Selecting which schemes are available will impact
not only the ease to write the compiler, but will also determine how efficient the
architecture can be?
All computers employ more than one addressing schemes to give programming
flexibility to the user by providing facilities such as pointers to memory, loop control,
indexing of data, program relocation and to reduce the number of bits in the operand
field of the instruction. Offering a variety of addressing modes can help reduce
instruction counts but having more modes also increases the complexity of the
machine and in turn may increase the average Cycles per Instruction (CPI). Before we
discuss the addressing modes let us discuss the notations being used in this section.
In the description that follows the symbols A, A l , A2 ...... etc. denote the content of
an operand field. Thus, Ai may refer to a data or a memory address. In case the
operand field is a register address, then the symbols ,R, R1, R2,... etc., are used. If C
denotes the contents (either of an operand field or a register or of a memory location),
then (C) denotes the content of the memory location whose address is C.
What is a virtual address? von Neumann had suggested that the execution of a
program is possible only if the program and data =&residing in memory. In such a
situation the progrzm length along with data and other space needed for execution
cannot exceed the total memory. However, it was found that at the time of execution,
the complete portion of data and instruction is not needed as most of the time only few
areas of the program are being referenced. Keeping this in mind a new idea was put
Instruction Strt
forward where only a required portion is kept in the memory while the rest of the Architecture
program and data reside in secondary storage. The data or program portion which are
stored on secondary storage are brought to memory whenever needed and the portion
of memory which is not needed is returned to the secondary storage. Thus, a program
size bigger than the actual physical memory can be executed on that machine. This is
called virtual memory. Virtual memory has been discussed in greater details as part of
the operating system.
The symbols D, Dl, D2, ..., etc. refer to actual operands to be used by instructions for
their execution. 1
Most of the machines employ a set of addressing modes. In this unit, we will describe
some very common addressing modes employed in most of the machines. A specific
addressing mode example, however, is given in Unit 1 of Block 4.
I I 1 I I
i
Immediate
, Memory
,Referen;
Register
Refereice
Displacement
Addrring
Stack
Addressing
II I
I Memory
Memory ~e~ister Register
f Direct Indirect Indirect
1-1
I
Main Memory , Main Memory
Instruction
LOAD D 500
O 0
......011 1
500
The second statement implies that the data is stored in the memory location
specified by effective address.
e In this addressing scheme only one memory reference is required to fetch the
operand.
The drawback of this scheme is that it requires two memory references to fetch
the actual operand. The first memory reference is to fetch the actual address of
the operand from the memory and the second to fetch the actual operand using
that address.
0 In this scheme the word length determines the size of addressable space, as the
actual address is stored in a Word. For example, the memory having a word size
of 32 bits can have 232indirect addresses.
Instruction
Register set
Instruction
b Aclclress of
- oprra~~J
-
" .-.,
e-
oprjra~ld w
Register set
The address capzbility of register indirect addressing scheme is deternlined by the size
L
of the register.
Fcr example, to address of an element B[i] of an array B[l], B[2], ....B[n], with each
element of the array stored in two consecutive locations, and the starting address of
the array is assumed to be 101, the operand field A in the instruction shall contain the
number 10 1 and the index register R will contain the value of the expression
(i - 1) x 2.
Tlius, for the first element of the array the index register will contain 0. For addressing
5th element of the array, the A- 101 whereas index register will contain:
Therefore, the address of the 5th element of array B is=lOl+8= 109. In B[5], however,
the element will be stored in location 109 and 110. 'To address any other element of
the array, changing the content of the index register will suffice.
As the index register is used for iterative applications, therefore, the value of index
register is incremented or decremented after each reference to it. In several systems
this operation is performed automatically during the course of an instruction cycle.
This feature is known as auto-indexing. Auto indexing can be auto-incrementing or
auto-decrementing. The choice of register to be used as an index register differs from
machine to machine. Some machines employ general-purpose registers for this
purpose while other machines may specify special purpose registers referred to as
ixtdex registers.
Ma~nMemory
The contents of the base register may be changed in the privileged mode only. No user
is allowed to change the contents of the base register. The base-addressing scheme
provides protection of users from one another.
Example 1: What would be the effective address and operand value for the following
LOAD instructions:
27A8
Instruction Set
The values are shown in the following table: Architecture
--
(jdressing Mode I Formulae for EA I
Data Value
I
k d e x Addressing
- / addressing mode
EA = A+(K)
D= ( E A L
1 56 + 2752 = 27AgH 1 10"
EA = A+ (B) 46 + 2260 = 2 2 A 6 ~ 2 5 ~
EA = (PC) + A 2532 + 36 = 2 5 6 8 ~ 7 0 ~
I 'Topof stack
Register
Implicit opetand
Figure li:Stack Addressing
(iii) Indirect addressing requires fewer memory accesses than that of direct
addressing.
However, a 32 bit instruction although will occupy double the space and can be
fetched at double the rate of a 16 bit instruction, but can not be doubly usefbl.
Memory organization
: if larger memory range is to be addressed, then
more bits may be required in address field.
: if the addressed memory is virtual memory then
memory range which is to be addressed by the
1
instruction is larger than physical meinory size.
Memory transfer length : instruction length should normally be equal to
data bus length or multiple of it.
Memory transfer : the data transfer rate from the memory ideally
should be equivalent to the processor speed. It
can become a bottleneck if processor executes
instructions faster than the rate of fetching the
instructions. One solution for such problem is
to use cache memory or another solution can be
to keep instruction short.
Instruction Set
Nonnally an instruction length is kept as a multiple of length of a character (that is 8 Architecture
bits), and equal to the length of fixed-point number. The term word is often used in
this context. Usually the word size is equal to the length of fixed point number or
equal to memory-transfer size. In addition, a word should store integral number of
characters. Thus, word size of 16 bit, 32 bit, 64 bit are to be coming very common and
$ hence the similar length of instructions are normally being used.
I
I
1.5.2 Allocation of Bits Among Opcode and Operand
?
The tradeoff here is between the numbers of bits of opcode versus the addressing
1 capabilities. An interesting development in this regard is the development of variable
I
length opcode.
Sorne of the factors that are considered for selection ofaddressing bits:
Number of addressing modes: The more are the explicit addressing modes the
more bits are needed for mode selection. However, some machines have implicit
modes of addressing.
Number of operands: Fewer number of operand references in an instruction
although require less bits yet result in longer programs. Present day machines
generally have two operand references in an instruction. Each of these operands
may need a addressing mode indicator field.
Register addressing versus memory addresses: The register references require
fewer bits in comparison to the memory addresses. In general, the number of user
visible registers provided is 16 to 32. Some of these registers may be used for
special purposes.
~ranularityof address: As far as memory references are concerned, granularity
implies whether an address is referencing a byte or a word at a time. This is more
relevant for machines, which have 16 bits, 32 bits and higher bits words. Byte
addressing although may be better for character manipulation, however, requires
more bits in an address. For example, memory of 4K words (1 word = 16 bit) is
to be addressed directly then it requires:
WORD Addressing = 4K words
= 212 words
3 12 bits are required for word addressing.
Pa important aspect about these variables length instructions is: "The CPU is not
aware about the bngth of next instruction which is to be fetched". This problem can
behandled if each instruction fetch is made equal to the size of the longest instruction.
The Central
1
Processing Unit
1.6 EXAMPLE OF INSTRUCTION FORMAT
Let us provide you a basic example by which you may be able to define the concept of
instruction format.
MIPS 2000 \
Let's consider the instruction format of a MIPS computer. MIPS is an acronym for
Microprocessor without Interlocked Pipeline Stages. It is a microprocessor
architecture developed by MIPS Computer Systems Inc. most widely known for
developing the MIPS architecture. The MIPS CPU family was one of the most
successful and flexible CPU designs throughout the 1990s. The MIPS CPU has a five-
stage CPU pipeline to execute multiple instructions at the same time. &ow what we
have introduced is a new term Pipelining. What else: the 5 stage pipeline, let us just
introduce it here. It defines the 5 steps of execution of instructions that may be
performed in an overlapped fashion. The following diagram will elaborate this
concept:
Figure15 Pipeline
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 bits long.
OP rs rt rd
I'
shamt funct II
6 bits 5 bits 5 bits 5 bits 5 bits 5 bits
Figure 16: A Sample Instruction Format of MIPS instruction
Instruction Format
All MIPS instructions are of the same size and are 32 bits long. MIPS designers chose
to keep all instructions of the same length, thereby requiring different kinds of
instruction formals for different kinds of instructions. For example, R-type (register)
or F:-format is used for arithmetic instructions (Figure 16). A second type of
instruction forma; is called i-type or i-format and is used by the data transfer
instructions.
1nst.ructionformat of I-type instructions is given below:
6 bits 5 bits
rt
5 bits
address
16 b~ts
J
I Figure 17: I-format of RTSC
The 16-bit address means a load word instruction can load any word within a region
of + 2" of the base register rs. Consider a load word instruction give11 below:
The rt field specifies the destination register, which recelves the result of the load.
I
(i) Instruction length should normally be equal to data bus length or multiple
of it.
(vi) Large number of operations can be provided in the instruction set, which
have variable-lengths of instructions. C]
1.7 SUMMARY
In this unit, we have explained various concepts relating to instructions. We have
discussed the significance of instruction set, various elements of an instruction,
instruction set design issues, different types of ISAs, various types of instructions and
various operations performed by the instructions, various addressing schemes. We
have also provided you the instruction format of MIPS machine. Block 4 Unit 1
29
The Central I
Processing Unit
contains a detailed instruction set of 8086 machine. You can refer to further reading
for instruction set of various machines.
3. -
(i) - b), d), f) ; (ii) a), c) ; (iii) - g) ; (iv) - e)
3. (i) True.
(ii) False.
(iii) False.
(iv) False
(ii) False.
(iii) False.
(iv) False.
(v) False.
(vi) True.