ITEC582 Chapter 12
ITEC582 Chapter 12
Chapter 12
Instruction Sets: Characteristics and Functions
1
Learning Objectives
2
1. Machine Instruction Characteristics
Elements of a Machine Instruction
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
3
What are the typical elements of a machine instruction?
These elements are as follows;
4
■ Result operand reference: The operation may produce a result.
■ Next instruction reference: This tells the processor where to
fetch the next instruction after the execution of this instruction is
complete.
What types of locations can hold source
and destination operands?
Source and result operands can be in one of four areas:
■ Main or virtual memory: ■ Processor register:
As with next instruction references, A processor contains one or more
the main or virtual memory address registers that may be referenced by
must be supplied machine instructions.
5
Elements of a Machine Instruction
7
Instruction Representation
Within the computer, each instruction is
represented by a sequence of bits.
The instruction is divided into fields,
8
Instruction Representation
9
Instruction Representation
Opcodes are represented by abbreviations,
called mnemonics, that indicate the
operation.
Common examples include:
◦ ADD - Add
◦ SUB - Subtract
◦ MUL - Multiply
◦ DIV - Divide
◦ LOAD - Load data from memory
◦ STOR - Store data to memory
10
Instruction Representation
Operands are also represented symbolically.
For example, the instruction ADD R,Y
(R R + Y ) may 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
11
Instruction Types
Consider a high-level language instruction that could be
expressed X=X+Y.
12
How are operations expressed in high level language
13
List and briefly discuss the four categories
of instruction types
Thus, the set of machine instructions must be
sufficient to express any of the instructions
from a high-level language.
14
Instruction Types
Arithmetic instructions provide computational capabilities for
processing numeric data.
Logic (Boolean) instructions operate on the bits of a word.
These operations are performed primarily on data in
processor registers.
I/O instructions are needed to transfer programs and data
into memory and the results of computations back out to the
user.
Test instructions are used to test the value of a data word or
the status of a computation.
Branch instructions are then used to branch to a different set
of instructions depending on the decision made.
15
Number of Addresses
One of the traditional ways of describing
processor architecture is in terms of the
number of addresses contained in each
instruction.
What is the maximum number of addresses
16
Thus, we would need a maximum of two addresses to reference
source operands for arithmetic and logic operations.
The result of an operation must be stored, suggesting a third
address, which defines a destination operand.
Finally, after completion of an instruction, the next instruction
must be fetched, and its address is needed.
17
In most architectures, many instructions have one, two, or three
operand addresses, with the address of the next instruction being
implicit (obtained from the program counter).
For example, the load and store multiple instructions of the ARM
architecture, designate up to 17 register operands in a single
instruction
Y = (A - B)/[C + (D * E)].
18
Number of Addresses
3 addresses format
◦ Operand 1, Operand 2, Result
◦ a = b + c;
With three-address instrcutions, each
instruction specifies two source operand
locations and a destination operand location.
This format is not common because it requires
a relatively long instruction format to hold the
three address references.
19
Write a program to compute by using three
address instructions.
20
Number of Addresses
2 addresses format
One address doubles as operand and result
◦ a=a+b
The two-address format reduces the space
requirement and the length of instruction but
requires some extra work.To avoid altering the
value of an operand, a MOVE instruction is used to
move one of the values to a result or temporary
location before performing the operation.
21
Write a program to compute by using two
address instructions.
22
Number of Addresses
Simpler yet is the one-address instruction. For
this to work, a second address must be
implicit.
This was common in earlier machines, with the
implied address being a processor register
known as the accumulator (AC). The
accumulator contains one of the operands and
is used to store the result.
23
Write a program to compute by using one
address instructions.
24
Number of Addresses
In fact, it is possible to do with zero addresses
for some instructions.
25
Number of Addresses
26
Write a program to compute by using zero
address instructions.
PUSH A
PUSH B
SUB
PUSH C
PUSH D
PUSH E
MUL
ADD
DIV
POP Y
27
Table below summarizes the interpretations to be placed on
instructions with zero, one, two, or three addresses. In each case in
the table, it is assumed that the address of the next instruction is
implicit, and that one operation with two source operands and one
result operand is to be performed
28
How Many Addresses?
More addresses per instruction results;
◦ More complex instructions
◦ Fewer instructions per program
◦ More registers
Fewer addresses per instruction results;
◦ Less complex instructions
◦ More instructions per program
◦ Faster fetch/execution of instructions
29
Instruction Set Design
The design of an instruction set is very
complex because it affects so many aspects
of the computer system.
The instruction set defines many of the
30
List and briefly explain five important instruction
set design issues
31
2. Types of Operands
32
Intel x86 Data Types
General
◦ 8 bit - byte
◦ 16 bit - word
◦ 32 bit - doubleword
◦ 64 bit - quadword
◦ 128 bit - double quadword
Integer
◦ A signed binary value contained in a byte, word, or
doubleword, using twos complement representation.
Ordinal
◦ An unsigned integer contained in a byte, word, or
doubleword.
Floating point
33
ARM Data Types
ARM processors support data types of
◦ 8 bits – byte
◦ 16 bits – halfword
◦ 32 bits - word
34
Types of Operations
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
35
Data Transfer
Transfer data from one location to another.
The data transfer instruction must specify the
location of the source and destination operands.
Each location could be memory, a register, or
the top of the stack.
If memory is involved:
◦ Determine memory address
◦ Perform virtual-to-actual-memory address
transformation
◦ Check cache
◦ Initiate memory read/write
36
37
38
39
Data Transfer
The data transfer instruction must specify several things
• The location of the source and destination operands must be
specified. Each location could be memory, a register, or the top
of the stack.
• The length of data to be transferred must be indicated.
40
In terms of processor action, data transfer operations are
perhaps the simplest type.
• If both source and destination are registers, then the
processor simply causes data to be transferred from one
register to another; this is an operation internal to the
processor.
• If one or both operands are in memory, then the processor
must perform some or all of the following actions:
41
Arithmetic
May involve data transfer, before and/or
after.
Perform function in ALU
42
Logical
Bitwise operations
◦ AND, OR, NOT, XOR, EQUALS
43
Logical and Arithmetical Operations
Most machines provide a variety of shift and
rotate functions
44
With a logical shift, the bits of a word are shifted left or right. On
one end, the bit shifted out is lost. On the other end, a 0 is shifted in.
A right arithmetic shift corresponds to a division by 2, with truncation
for odd numbers. An arithmetic left shift corresponds to a
multiplication by 2
Rotate, or cyclic shift, operations preserve all of the bits being
operated on. One use of a rotate is to bring each bit
successively into the leftmost bit, where it can be identified by
testing the sign of the data
45
Conversion
46
47
Input/Output
Issue command to I/O module
48
System Control
System control instructions are those that can
be executed only while the processor is in a
certain privileged state or is executing a
program in a special privileged area of
memory.
Typically, these instructions are reserved for
49
Transfer of Control
A significant fraction of the instructions in any
program have as their function changing the
sequence of instruction execution.
50
Branch instructions :
A branch instruction, also called a jump instruction, has as one of its
operands the address of the next instruction to be executed.
Most often, the instruction is a conditional branch instruction.
51
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 if result is zero.
BRO X : Branch to location X if overflow occurs
Another approach that can be used with a three-address
instruction format is to perform a comparison and specify a
branch in the same instruction.
For example,
BRE R1, R2, X
(Branch to X if contents of R1 = contents of R2)
52
Branch Instruction
53
Skip Instruction
Another form of transfer- of- control instruction is the skip
instruction. The skip instruction includes an implied address.
A typical example is the increment-and-skip-if-zero (ISZ)
instruction.
54
Procedure Calls
A procedure is a self contained computer program that is
incorporated into a larger program.
At any point in the program the procedure may be invoked, or
called
Two principal reasons for the use of procedures are economy
and modularity.
55
56
Use of stack
When the processor executes a call, it places the return
address on the stack. When it executes the return, it uses the
address on the stack.
57