COA Chapter 3 final edited
COA Chapter 3 final edited
Instruction Sets:
Characteristics , Functions,
Addressing Modes and
Formats
1
Introduction
• The operation of the processor is determined by the instructions
it executes, referred to as machine instructions or computer
instructions.
• The collection of different instructions that the
processor can execute is referred to as the processor’s
instruction set.
• The computer designer and the computer programmer can view
the same machine as the machine instruction set. From the
designer’s point of view, the machine instruction set provides the
functional requirements for the processor: implementing the
processor is a task that in large part involves implementing the
machine instruction set.
• The user who chooses to program in machine language becomes
aware of the register and memory structure, the types of data
directly supported by the machine, and the functioning of the
ALU. 2
What is an Instruction Set?
The complete collection of instructions that are
understood /Executed by a CPU.
Instruction Set can be:
• Machine Code.
• Binary code.
• They can be represented by assembly codes.
Machine Instruction set types can be/Function of
Instruction Sets/:
• Data processing:
• Data storage (main memory):
• Data movement (I/O):
• Program flow control : 3
Elements/Types/ of a Machine
Instruction set
• Operation code (Opcode): Do this, Specifies the operation
to be performed (e.g., ADD, I/O). The operation is specified by a
binary code, known as the operation code,or opcode.
• Source Operand Reference: To this, operands that are
inputs for the operation.
• Result Operand reference: Put the answer here, The
operations that produce a result.
• Next Instruction Reference: When you have done that,
do this, tells the processor where to fetch the
next instruction after the execution of this
instruction is complete.
4
Source and Result operands can be in one of four
areas:
• Main or virtual memory: As with next instruction
references, the main or virtual memory address must be supplied.
• Processor Register: With rare exceptions, a processor
contains one or more registers that may be referenced by
machine instructions. If only one register exists, reference to it
may be implicit. If more than one register exists, then each
register is assigned a unique name or number, and the instruction
must contain the number of the desired register.
• Immediate: The value of the operand is contained in a field in
the instruction being executed.
• I/O device: The instruction must specify the I/O module and
device for the operation. If memory-mapped I/O is used, this is
just another main or virtual memory address. 5
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. A simple example of an instruction
format is shown in the Figure below.
• Most instruction sets, has more than one format is
used. During instruction execution, an instruction is
read into an instruction register (IR) in the processor.
• The processor must be able to extract the data from the
various instruction fields to perform the required
operation. it has become common practice to use a
symbolic representation of machine instructions. An
example of this was used for the IAS(institute for
advanced study) instruction set, in Table below. 6
• Opcodes(Operation code) :are represented by abbreviations,
called mnemonics, that indicate the types os operation to
beperformed.
Common Opcodes(Operation code) are includes the following:
• ADD Add
• SUB Subtract
• MUL Multiply
• DIV Divide
• LOAD Load data from memory.
• STOR Store data to memory.
• Operands are represented symbolically. For example, the
instruction ADD R, Y mean add the value contained in data
location Y to the contents of register R. In this example, Y refers to
the address of a location in memory, and R refers to a particular
register. Note that the operation is performed on the contents of a
location, not on its address. 7
• A computer should have a set of instructions that allows the user
to formulate any data processing task. Another way to view it is
to consider the capabilities of a high-level programming language.
• Any program written in a high-level language must be translated
into machine language to be executed. Thus, the set of machine
instructions must be sufficient to express any of the instructions
from a high-level language.
Machine instructions set can be:
Data processing: Arithmetic and logic instructions
Data storage: Movement of data into or out of register
and or memory locations.
Data movement: I/O instructions.
Control: Test and branch instructions.
8
Simple Machine Instruction Formats
9
Types of operands
Machine instructions operate on data. The most
important general categories of data are :
• Addresses.
• Numbers.
• Characters.
• Logical data.
10
Data Transfer
• The most fundamental type of machine
instruction is the data transfer instruction.
• The data transfer instruction must specify several
things.
1.The location of the source and destination
operands must be specified. Each location could
be memory, a register, or the top of the stack.
2. The length of data to be transferred must be
indicated.
3. The mode of addressing for each operand must
be specified. 11
Types of Operations (Opcodes)
The number of different opcodes varies widely
from machine to machine. However, the same
general types of operations are found on all
machines. A useful and typical categorization is the
following:
• Data transfer.
• Arithmetic.
• Logical.
• Conversion.
• I/O.
• System control.
• Transfer of control. 12
13
14
15
Number of Addresses
• 3 addresses
– Operand 1, Operand 2, Result
– a = b + c;
– May be a forth - next instruction (usually implicit)
– Not common
– Needs very long words to hold everything
16
• 2 addresses
– One address doubles as operand and result
–a=a+b
– Reduces length of instruction.
– Requires some extra work.
• Temporary storage to hold some results
• 1 address
– Implicit second address.
– Usually a register (accumulator).
– Common on early machines.
17
• 0 (zero) addresses
– All addresses implicit
– Uses a stack
– e.g. push a
– push b
– add
– pop c
–c=a+b
18
Example
Write a Three, Two and One
Instruction set for the following
expression.
19
20
21
22
Class work 10%
• Write A Three, two and
One Address Instruction
Set for the following
Expression.
X=(A + B X C)/( D- E x
F+G*H) 23
More Addresses Vs Fewer Addresses
• More addresses
– More complex instructions sets.
– More Registers.
• Inter-register operations are quicker
– Fewer steps of instructions per program.
• Fewer addresses
– Less complex instructions sets.
– More instructions per program.
– Faster execution of instructions.
24
Design Issues of Instruction Sets
• Operation Repertoire( Range).
– How many Operations are used?
– What can they do?
– How complex are they?
• Data types: the types of data upon
which operations are performed.
• Instruction formats.
– Length of op code field
– Number of addresses 25
• Registers
–Number of CPU registers available
–Which operations can be performed
on which registers?
• Addressing: The mode or modes by
which the address of an operand is
specified.
26
Types of Operand
• Addresses
• Numbers
– Integer/floating point
• Characters
– ASCII etc.
• Logical Data
– Bits or flags
27
Data Transfer
• Specify
– Source
– Destination
– Amount of data
• May be different instructions for different
movements Or one instruction and different
addresses.
28
Arithmetic
• Add, Subtract, Multiply, Divide
• Signed Integer
• Floating point
• May include
– Increment (a++)
– Decrement (a--)
– Negate (-a)
• Logical Operators
– Bitwise operations
– AND, OR, NOT
29
• May be:
Input/output
– specific instructions.
– done using data movement instructions
(memory mapped).
– done by a separate controller (DMA).
30
Addressing Modes
and Formats
31
Types of Addressing Modes
• Immediate Addressing Modes
• Direct Addressing Modes
• Indirect Addressing Modes
• Register Addressing Modes
• Register Indirect Addressing Modes
• Displacement (Indexed) Addressing
Modes
• Stack Addressing Modes
32
In this section, we use the following notation
A = contents of an address field in the instruction.
R = contents of an address field in the instruction
that refers to a register.
EA = actual (effective) address of the location
containing the referenced operand.
(X) = contents of memory location X or register X.
33
Immediate Addressing
• The simplest form of addressing is immediate
addressing, in which the operand value is present in the
instruction.
• The operand value is present in the instruction.
i.e Operand is part of instruction.
Operand = A
• This mode can be used to define and use constants or
set initial values of variables.
• No memory reference to fetch data.
• Fast.
• Has Limited range.
34
• The advantage of immediate addressing is that
no memory reference other than the instruction
fetch is required to obtain the operand, thus
saving one memory or cache cycle in the
instruction cycle.
• The disadvantage is that the size of the number
is restricted to the size of the address field is
small compared with the word length.
35
Immediate Addressing Diagram
Instruction
Opcode
Operand
36
Direct Addressing
• With direct addressing, the length of the address field is
usually less than the word length, this limiting the
address range.
• Address field contains address of operand.
• Effective address (EA) = address field (A).
EA = (A)
• Single memory reference to access data.
• No additional calculations to work out effective address.
• Limited address space.
37
• The technique was common in earlier
generations of computers but is not common on
contemporary architectures.
• It requires only one memory reference and no
special calculation. The obvious limitation is that
it provides only a limited address space.
38
Direct Addressing Diagram
Instruction
Opcode Address A
Memory
Operand
39
Indirect Addressing
• With direct addressing, the length of the address field is usually
less than the word length, thus limit the address range.
• Memory cell pointed by address field contains the address of
(pointer to) the operand.
EA = (A)
– Look in A, find address (A) and look there for operand
e.g. ADD (A)
– Add contents of cell pointed to by contents of A to accumulator
• Uses Large address space.
• An Address space of 2n available, where n =the no of word
length.
• May be nested, multilevel, cascaded
– e.g. EA = (((A)))
• Multiple memory accesses to find operand, Hence slower.
40
Indirect Addressing Diagram
Instruction
Opcode Address A
Memory
Pointer to operand
Operand
41
Register Addressing
• Register addressing is similar to direct addressing.
• The only difference is that the address field refers to a
register rather than a main memory address.
• Operand is held in register named in address
filed.
• EA = R
• Limited number of registers used.
• Very small address field needed.
– Shorter instructions
– Faster instruction fetch
42
Register Addressing
• No memory access
• Very fast execution
• Very limited address space
• Multiple registers helps for better performance.
– Requires good assembly programming or compiler
writing.
• Similar to Direct addressing
43
• The advantages of register addressing are that
– only a small address field is needed in the
instruction.
– no time-consuming memory references are
required.
• The memory access time for a register internal
to the processor is much less than that for a
main memory address. The disadvantage of
register addressing is that the address space is
very limited.
44
Register Addressing Diagram
Instruction
Opcode Register Address R
Registers
Operand
45
Register Indirect Addressing
• Register indirect addressing is analogous to
indirect addressing.
• Analogous to indirect addressing.
– EA = (R)
• Uses one less memory reference than indirect
addressing.
46
• The advantages and limitations of register
indirect addressing are basically the same as for
indirect addressing. In both cases, the address
space limitation (limited range of addresses) of
the address field is overcome by having that field
refer to a word length location containing an
address.
• In addition, register indirect addressing uses one
less memory reference than indirect addressing.
47
Register Indirect Addressing Diagram
Instruction
Opcode Register Address R
Memory
Registers
48
Displacement Addressing
• A very powerful mode of addressing combines
the capabilities of direct addressing and register
indirect addressing.
• Also known as displacement addressing.
• Displacement addressing requires that the
instruction have two address fields, at least one
of which is explicit. The value contained in one
address field (value = A)
EA = A + (R)
• Address field hold two values
– A = base value
– R = register that holds displacement or vice versa. 49
12. Displacement Addressing Diagram
Instruction
Opcode Register R Address A
Memory
Registers
50
Relative Addressing
• Relative addressing, also called PC-relative addressing,
the implicitly referenced register is the program counter
(PC). That is, the next instruction address is added to the
address field to produce the EA.
• Typically, the address field is treated as a twos
complement number for this operation. Thus, the
effective address is a displacement relative to the
address of the instruction.
• Most memory references are relatively near to the
instruction being executed, then the use of relative
addressing saves address bits in the instruction.
51
Base-Register Addressing
• A holds displacement
• R holds pointer to base address
• R may be explicit or implicit
• e.g. segment registers in 80x86
52
• The referenced register contains a main memory
address, and the address field contains a
displacement (usually an unsigned integer
representation) from that address. The register
reference may be explicit or implicit.
• Base-register addressing also exploits the locality
of memory references. It is a convenient means
of implementing segmentation.
53
Indexed Addressing
• In Indexed Addressing, the address field
references a main memory address, and
the referenced register contains a positive
displacement from that address. Note that
this usage is just the opposite of the
interpretation for base-register addressing.
• In indexing, it generally contains more bits
than an address field in a comparable base-
register instruction.
54
Indexed Addressing
• A = base
• R = displacement
• EA = A + R
• Good for accessing arrays
– EA = A + R
– R++
55
Summary
Table 11.1 Basic
Addressing Modes. Read
and copy page 403.
56
Summary
◆ The essential elements of a computer instruction are the opcode,
which specifies the operation to be performed; the source and
destination operand references, which specify the input and
output locations for the operation; and a next instruction
reference, which is usually implicit.
◆ Opcodes specify operations in one of the following general
categories:arithmetic and logic operations; movement of data
between two registers,register and memory, or two memory
locations; I/O; and control.
◆ Operand references specify a register or memory location of
operand data.The type of data may be addresses, numbers,
characters, or logical data. ndle both styles.
57
Summary
◆ A common architectural feature in processors is the use of a
stack, which may or may not be visible to the programmer. Stacks
are used to manage procedure calls and returns and may be
provided as an alternative form of addressing memory.The basic
stack operations are PUSH,POP, and operations on the top one or
two stack locations. Stacks typically are implemented to grow
from higher addresses to lower addresses.
◆ Byte-addressable processors may be categorized as big endian,
little endian, or bi-endian. A multibyte numerical value stored
with the most significant byte in the lowest numerical address is
stored in big-endian fashion. The little-endian style stores the
most significant byte in the highest numerical address.A bi-endian
processor can ha
58