0% found this document useful (0 votes)
29 views

ITEC582 Chapter 12

Here is a program to compute Y = (A - B)/[C + (D * E)] using three-address instructions: LOAD R1, A ; Load value of A into register R1 LOAD R2, B ; Load value of B into register R2 SUB R3, R1, R2 ; R3 = R1 - R2 LOAD R4, C ; Load value of C into register R4 LOAD R5, D ; Load value of D into register R5 LOAD R6, E ; Load value of E into register R6 MUL R7, R5, R6 ; R7 = R5 * R6 ADD

Uploaded by

linhnmhe172617
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

ITEC582 Chapter 12

Here is a program to compute Y = (A - B)/[C + (D * E)] using three-address instructions: LOAD R1, A ; Load value of A into register R1 LOAD R2, B ; Load value of B into register R2 SUB R3, R1, R2 ; R3 = R1 - R2 LOAD R4, C ; Load value of C into register R4 LOAD R5, D ; Load value of D into register R5 LOAD R6, E ; Load value of E into register R6 MUL R7, R5, R6 ; R7 = R5 * R6 ADD

Uploaded by

linhnmhe172617
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 57

Eastern Mediterranean University

School of Computing and Technology


Master of Technology

Architecture and Hardware (ITEC582 )

Chapter 12
Instruction Sets: Characteristics and Functions

1
Learning Objectives

After studying this chapter, you should be able to

 Present an overview of essential characteristics of machine


instructions.
 Describe the types of operands used in typical machine
instruction sets.
 Describe the types of operands supported by typical machine
instruction sets.

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

the processor can execute is referred to as


the processor’s instruction set.
 Each instruction must contain the information

required by the processor for execution.

3
 What are the typical elements of a machine instruction?
These elements are as follows;

Operation code , Source operand reference, Result operand reference


and Next instruction reference

■ Operation code: 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: The operation may involve one or
more source operands, that is, operands that are inputs for the
operation.

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.

■ Immediate: ■ I/O device:


The value of the operand is contained The instruction must specify the I/O
in a field in the instruction being module and device for the operation.
executed

5
Elements of a Machine Instruction

 Figure shows the steps involved in instruction execution and


defines the elements of a machine instruction.

Instruction Cycle State Diagram


6
Instruction Address Calculation − The address of the next instruction is
computed. A permanent number is inserted to the address of the earlier
instruction.
Instruction Fetch − The instruction is read from its specific memory
location to the processor.
Instruction Operation Decoding − The instruction is interpreted and the
type of operation to be implemented and the operand(s) to be used are
decided.
Operand Address Calculation − The address of the operand is evaluated
if it has a reference to an operand in memory or is applicable through the
Input/Output.
Operand Fetch − The operand is read from the memory or the I/O.
Data Operation − The actual operation that the instruction contains is
executed.
Store Operands − It can store the result acquired in the memory or
transfer it to the I/O.

7
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.

A simple instruction format

8
Instruction Representation

 In machine code each instruction has a


unique bit pattern.

 For human consumption (programmers) a


symbolic representation of machine
instructions is used.

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

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.

11
Instruction Types
 Consider a high-level language instruction that could be
expressed X=X+Y.

 This statement instructs the computer to add the value


stored in Y to the value stored in X and put the result in
X.

 Let us assume that the variables X and Y correspond to


memory locations 513 and 514. This operation could be
accomplished with three instructions:
1. Load a register with the contents of memory location 513
2. Add the contents of memory location 514 to the register
3. Store the contents of the register in memory location 513

12
 How are operations expressed in high level language

and machine language ?


 This is a typical relationship between a high-
level language and a machine language.
 A high-level language expresses operations

in a concise algebraic form, using variables.


 A machine language expresses operations in

a basic form involving the movement of data


to or from registers.
 Therefore, a computer should have a set of

instructions that allows the user to formulate


any data processing task.

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.

 With this in mind we can categorize


instruction types as follows:
◦ Data processing: arithmetic and logic instructions
◦ Data storage (main memory): data in/out to/from
registers, memory locations
◦ Data movement (I/O): I/O instructions
◦ Program flow control: test and branch instructions

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

one might need in an instruction?


 All arithmetic and logic operations are either

unary (one source operand) or binary (two


source operands).

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.

 If an instruction contains four addresses, what might be the


purpose of each address?

This line of reasoning suggests that an instruction could


plausibly be required to contain four address references: two
source operands, one destination operand, and the address of the
next instruction.

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

Compare typical one-, two-, and three- address instructions that


could be used to compute

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.

 Zero-address instructions are applicable to a


special memory organization, called a stack. A
stack is a last-in-first-out set of locations.

 The stack is in a known location and, often, at


least the top two elements are in processor
registers.

25
Number of Addresses

 Thus, zero-address instructions would


reference the top two stack elements.

 For example, c = a + b can be implemented by


zero addresses as:
◦ push a
◦ push b
◦ add
◦ pop c

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

 For reasons of flexibility and ability to use multiple


registers, most contemporary machines employ a
mixture of two- and three-address 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

functions performed by the processor and


thus has a significant effect on the
implementation of the processor.
 The instruction set is the programmer’s

means of controlling the processor.

30
 List and briefly explain five important instruction
set design issues

 Instruction set design issues includes:


◦ Operation repertoire
 How many operations ? What can they do?
 How complex are they?
◦ Data types
◦ Instruction formats
 Length of op code field
 Number of addresses
◦ Registers
 Number of CPU registers available and which operations
can be performed on which registers?
◦ Addressing modes by which the address of an operand is
specified.

31
2. Types of Operands

 What types of operands are typical in machine instruction sets?

 The most important general categories of


data are:
◦ Addresses (In many cases, some calculation must
be performed on the operand reference in an
instruction to determine the main or virtual
memory address.)
◦ Numbers (Integer/floating point)
◦ Characters (ASCII etc.)
◦ Logical Data (Bits or flags)

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

 Majority of implementations do not provide


floating-point hardware
◦ Saves power and area
◦ Floating-point arithmetic implemented in software
◦ ARM supports optional floating-point coprocessor that
supports single- and double-precision floating point data
types defined in IEEE 754

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.

• All instructions with operands, the mode of addressing for


each operand must be specified.

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:

1. Calculate the memory address, based on the address


mode.
2. If the address refers to virtual memory, translate from
virtual to real memory address.
3. Determine whether the addressed item is in cache.
4. If not, issue a command to the memory module.

41
Arithmetic
 May involve data transfer, before and/or
after.
 Perform function in ALU

◦ Add, Subtract, Multiply, Divide


◦ May include
 Increment (a++)
 Decrement (a--)
 Absolute (|a|)
 Negate (-a)
 Set flags

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

 Conversion instructions are those that change


the format or operate on the format of data.

 An example is converting from decimal to


binary.

 May involve special logic to perform


conversion.

46
47
Input/Output
 Issue command to I/O module

 There are a variety of approaches including


programmed I/O, interrupt driven I/O, DMA,
and the use of an I/O processor.

 Many implementations provide only a few I/O


instructions, with the specific actions
specified by parameters, codes, or command
words.

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

the use of the operating system.


◦ For example, a system control instruction may read
or alter a control register.

49
Transfer of Control
 A significant fraction of the instructions in any
program have as their function changing the
sequence of instruction execution.

 For these instructions, the operation performed by


the processor is to update the program counter to
contain the address of some instruction in
memory.

 The most common transfer of control operations


found in instruction sets are branch, skip and
procedure call.

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.

The branch is made (update program counter to equal address


specified in operand) only if a certain condition is met.
Otherwise, the next instruction in sequence is executed

A branch instruction in which the branch is always taken is an


unconditional branch.

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.

The procedure mechanism involves two basic instructions: a call


instruction that branches from the present location to the
procedure, and a return instruction that returns from the
procedure to the place from which it was called. Both of these are
forms of branching instructions.

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

You might also like