You are on page 1of 58

Characteristics and Functions Addressing Modes

CSC 213: Computer Architecture


Lecture 5: Instruction Sets: Characteristics and Functions,
Addressing Modes

November 16, 2021

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Agenda

1 Characteristics and Functions


Instruction Characteristics
Types of operands
Types of operations

2 Addressing Modes

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Instruction Set Architecture (ISA)

Serves as an interface between software and hardware.


Provides a mechanism by which the software tells the
hardware what should be done.

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Interface Design

A good interface:
Lasts through many implementations (portability,
compatability)
Is used in many different ways (generality)
Provides convenient functionality to higher levels
Permits an efficient implementation at lower levels

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Instruction Set Design Issues

Instruction set design issues include:


Where are operands stored?
registers, memory, stack, accumulator
How many explicit operands are there?
0, 1, 2, or 3
How is the operand location specified?
register, immediate, indirect, . . .
What type & size of operands are supported?
byte, int, float, double, string, vector, . . .
What operations are supported?
add, sub, mul, move, compare, . . .

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Evolution of Instruction Sets

Single Accumulator (EDSAC 1950, Maurice Wilkes)


Accumulator + Index Registers
(Manchester Mark I, IBM 700 series 1953)

Separation of Programming Model


from Implementation

High-level Language Based Concept of a Family


(B5000 1963) (IBM 360 1964)

General Purpose Register Machines

Complex Instruction Sets Load/Store Architecture


(Vax, Intel 432 1977-80) (CDC 6600, Cray 1 1963-76)

CISC RISC
Intel x86, Pentium (MIPS,Sparc,HP-PA,IBM RS6000,PowerPC . . .1987)

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

What is an Instruction Set?

The complete collection of instructions that are understood by


a CPU
Machine language: binary representation of operations and
(addresses of) arguments
Assembly language: mnemonic representation for humans,
e.g., OP A,B,C (meaning A ← OP(B,C))

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Elements of an Instruction

Operation code (opcode)


Do this: ADD, SUB, MPY, DIV, LOAD, STOR
Source operand reference
To this: (address of) argument of op, e.g. register, memory
location
Result operand reference
Put the result here e.g. register, memory location
Next instruction reference (often implicit)
When you have done that, do this: BR

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Instruction Representation

In machine code each instruction has a unique bit pattern


For human consumption (well, programmers anyway) a
symbolic representation is used e.g. ADD, SUB, LOAD
Operands can also be represented in this way - ADD A,B

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Simple Instruction Format

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Instruction Types

Data processing
Data storage (main memory)
Data movement (internal transfer and I/O)
Program flow control

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Types of Operand references

Source and result operands can be in one of four areas:


Main or virtual memory
I/O devices
If memory-mapped I/O is used, this is just another main or
virtual memory address
Processor Registers
Immediate

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Number of Addresses

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

How Many References

More addresses
More complex (powerful?) instructions
Less instructions per program
slower instruction cycle
Fewer addresses
Less complex (powerful?) instructions
More instructions per program, e.g. data movement
Faster instruction cycle

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Example - Number of Addresses

Compute
(A − B)
(C + (D ∗ E ))
assuming each of them is in a read-only register which cannot
be modified.
Additional registers can be used if needed.

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Example - 3 Address Instructions

OP Result, Operand 1, Operand 2


Not common
Needs very long words to hold everything

Instruction Comment
SUB Y, A, B Y←A-B
MPY T, D, E T←DxE
ADD T, T, C T←T+C
DIV Y, Y, T Y←Y/T

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Example - 2 Address Instructions

One address doubles as operand and result


Reduces length of instruction
Requires some extra work: temporary storage

Instruction Comment
MOVE Y, A Y←A
SUB Y, B Y←Y-B
MOVE T, D T←D
MPY T, E T←TxE
ADD T, C T←T+C
DIV Y, T Y←Y/T

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Example - 1 Address Instructions

Implicit second address, usually a register (accumulator, AC)

Instruction Comment
LOAD D AC ← D
MPY E AC ← AC xE
ADD C AC ← AC +C
STOR Y Y ← AC
LOAD A AC ← A
SUB B AC ← AC -B
DIV Y AC ← AC /Y
STOR Y Y ← AC

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Characteristics

Example - 0 (zero) Address Instructions

All addresses implicit, e.g. ADD


Uses a stack
Example - Compute c = a + b
push a
push b
add
pop c

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operands

Types of Operands

Addresses: immediate, direct, indirect, stack


Numbers
Integer/floating point
Characters
ASCII etc.
Logical Data
Bits or flags

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operands

Numbers

All machine languages include numeric data types


Numbers stored in a computer are limited:
Limit to the magnitude of numbers representable on a machine
In the case of floating-point numbers, a limit to their precision
Three types of numerical data are common in computers:
Binary integer or binary fixed point
Binary floating point
Decimal
Packed decimal

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operands

Characters

A common form of data is text or character strings


Textual data in character form cannot be easily stored or
transmitted by data processing and communications systems
because they are designed for binary data
Most commonly used character code is the International
Reference Alphabet (IRA) or the American Standard Code for
Information Interchange (ASCII)
Another code used to encode characters is the Extended
Binary Coded Decimal Interchange Code (EBCDIC)

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operands

Logical Data

An n-bit unit consisting of n 1-bit items of data, each item


having the value 0 or 1
Two advantages to bit-oriented view:
Memory can be used most efficiently for storing an array of
Boolean or binary data items in which each item can take on
only the values 1 (true) and 0 (false)
To manipulate the bits of a data item

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Instruction Types

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Data Transfer

Specify
Source
Destination
Amount of data
May be different instructions for different movements
Or one instruction and different addresses

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Arithmetic

Basic arithmetic operations of add, subtract, multiply, and


divide
Provided for signed integer (fixed-point) numbers, often also
for floating-point and packed decimal numbers
May include
Increment (a++)
Decrement (a–)
Negate (-a)

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Basic Logical Operations

Bitwise operations, AND, OR, NOT, XOR, TEST, CMP, SET


...
Shifting and rotating functions

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Shift and Rotate Operations

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Example - Shift and Rotate Operations

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Conversion

E.g. Binary to Decimal

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Input/Output

May be specific instructions


May be done using data movement instructions (memory
mapped)
May be done by a separate controller (DMA)
Variety of approaches taken:
Isolated programmed I/O
Memory-mapped programmed I/O
DMA
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

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Systems Control

Privileged instructions
CPU needs to be in specific state
Ring 0 on 80386+
Kernel mode
For operating systems use

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Transfer of Control

Most common transfer-of-control operations found in


instruction sets:
Branch
e.g. branch to x if result is zero
Skip
e.g. increment and skip if zero
– ISZ Register1
Procedure call

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Branch Instruction

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Procedures

Self-contained computer program that is incorporated into a


larger program
Two principal reasons for use of procedures:
Economy - A procedure allows the same piece of code to be
used many times
Modularity
Procedures involves two basic instructions:
A call instruction that branches from the present location to
the procedure
Return instruction that returns from the procedure to the place
from which it was called

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Nested Procedures

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Types of operations

Use of Stack to Implement Nested Procedures

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Addressing Modes

Immediate
Direct
Indirect
Register
Register indirect
Displacement
Stack

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Basic Addressing Modes

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Immediate Addressing

Simplest form of addressing


Operand = A, e.g. ADD 5
This mode can be used to define and use constants or set
initial values of variables
Advantage:
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
Disadvantage:
The size of the number is restricted to the size of the address
field, which, in most instruction sets, is small compared with
the word length

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Immediate Addressing - Diagram

Instruction

Opcode Operand

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Direct Addressing

Address field contains address of operand


Effective address (EA) = address field (A)
e.g. ADD A
Add contents of cell A to accumulator
Look in memory at address A for operand
Single memory reference to access data
No additional calculations to work out effective address
Limited address space

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Direct Addressing - Diagram

Instruction

Opcode Address A
Memory

Operand

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Indirect Addressing
Reference to the address of a word in memory which contains
a full-length address of the operand
EA = (A)
Parentheses are to be interpreted as meaning contents of
Advantage: For a word length of N an address space of 2N is
now available
Disadvantage:
Instruction execution requires two memory references to fetch
the operand, one to get its address and a second to get its
value
A rarely used variant of indirect addressing is multilevel or
cascaded indirect addressing
EA = ( . . . (A) . . . )
multiple memory accesses required to find operand

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Indirect Addressing - Diagram

Instruction

Opcode Address A
Memory

Pointer to operand

Operand

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Register Addressing

Address field refers to a register rather than a main memory


address
EA = R
Advantages:
Only a small address field is needed in the instruction
No time-consuming memory references are required
Disadvantage:
The address space is very limited

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Register Addressing - Diagram

Instruction

Opcode Register Address R


Registers

Operand

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Register Indirect Addressing

Analogous to indirect addressing


The only difference is whether the address field refers to a
memory location or a register
EA = (R)
Address space limitation of the address field is overcome by
having that field refer to a word-length location containing an
address
Uses one less memory reference than indirect addressing

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Register Indiret Addressing - Diagram

Instruction

Opcode Register Address R


Memory

Registers

Pointer to Operand Operand

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Displacement Addressing
Combines the capabilities of direct addressing and register
indirect addressing
EA = A + (R)
Requires that the instruction have two address fields, at least
one of which is explicit
The value contained in one address field (value = A) is used
directly
The other address field refers to a register whose contents are
added to A to produce the effective address
Most common uses:
Relative addressing
Base-register addressing
Indexing

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Displacement Addressing - Diagram

Instruction

Opcode Register R Address A


Memory

Registers

Pointer to Operand + Operand

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Relative Addressing

The implicitly referenced register is the program counter (PC)


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
Exploits the concept of locality
Saves address bits in the instruction if most memory
references are relatively near to the instruction being executed

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Base-Register Addressing

The referenced register contains a main memory address and


the address field contains a displacement from that address
The register reference may be explicit or implicit
Exploits the locality of memory references
Convenient means of implementing segmentation
In some implementations a single segment base register is
employed and is used implicitly
In others the programmer may choose a register to hold the
base address of a segment and the instruction must reference
it explicitly

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Indexed Addressing
The address field references a main memory address and the
referenced register contains a positive displacement from that
address
The method of calculating the EA is the same as for
base-register addressing
An important use is to provide an efficient mechanism for
performing iterative operations
Autoindexing
Automatically increment or decrement the index register after
each reference to it
EA = A + (R)
(R) ← (R) + 1
Postindexing - Indexing is performed after the indirection
Preindexing - Indexing is performed before the indirection

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Stack Addressing

A stack is a reserved block of locations


Items are appended to the top of the stack so that the block
is partially filled
Associated with the stack is a pointer whose value is the
address of the top of the stack
The stack pointer is maintained in a register
Thus references to stack locations in memory are in fact
register indirect addresses
Is a form of implied addressing
The machine instructions need not include a memory
reference but implicitly operate on the top of the stack

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Formats

Layout of bits in an instruction


Includes opcode
Includes (implicit or explicit) operand(s)
Usually more than one instruction format in an instruction set

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Instruction Length

Affected by and affects:


Memory size
Memory organization
Bus structure
CPU complexity
CPU speed
Trade off between powerful instruction repertoire and saving
space

CSC 213: Computer Architecture


Characteristics and Functions Addressing Modes

Allocation of Bits

Number of addressing modes


Number of operands
Register versus memory
Number of register sets
Address range
Address granularity

CSC 213: Computer Architecture

You might also like