Dr.
Hadiza Ali Umar
What is an Address Mode?
The address field or fields in a typical instruction format are relatively small. It is utilised to
reference a large range of locations in main memory or, for some systems, virtual memory. To
achieve this objective, a variety of addressing techniques have been employed. They all involve
some trade-off between address range and/or addressing flexibility, on the one hand, and the
number of memory references in the instruction and/or the complexity of address calculation, on
the other.
Addressing techniques:
• Immediate
• Direct
• Indirect
• Register
• Register indirect
• Displacement
• Stack
Instruction
• Instruction format defines how instructions are represented in a
computer’s memory. There are different types of instruction formats,
including zero, one, two, and three-address instructions. It defines how the
CPU decodes and executes instructions.
• Opcode: This field specifies the operation to be performed by the CPU,
such as addition, subtraction, or data transfer.
• Operands: These fields contain the data or references (addresses) to data
on which the operation acts.
• Addressing Mode: It consists of techniques used by the CPU to identify the
location of the operand(s) needed for executing an instruction. They
provide rules for interpreting the address field in an instruction, helping the
CPU fetch operands correctly. Examples of addressing modes include
direct, indirect, or immediate addressing.
Instruction
• An instruction comprises groups called fields. These fields include:
The Operation code (Opcode) field determines the process that needs
to be performed. The Address field contains the operand's location,
i.e., register or memory location. The Mode field specifies how the
operand locates.
Types of Operands
• Machine instructions operate on data. The most important
general categories of data are:-
• Addresses
• Numbers
• Characters
• Logical data
Opcodes
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
Instruction Types
• Data transfer: registers, main memory, stack or I/O
• Data processing: arithmetic, logical
• Control: systems control, transfer of control
Instruction Cycle
• The instructions of a program are carried out by a process called the
instruction cycle.
• The instruction cycle consists of these phases:
– Fetch an instruction from memory
– Decode the instruction
– Read the effective address from memory if the operand has an
indirect address.
– Execute the instruction.
Computer Instructions
• The basic computer has three instruction code formats:
• Memory-reference format – where seven 3-bit opcodes are followed by a 12-
bit memory address and preceded by a bit which indicates whether direct or
indirect addressing is being used.
• Register-reference format – where 01112 is followed by 12 bits which
indicate a register instruction.
• Input-output format – where 11112 is followed by 12 bits which indicate an
input-output instruction.
• In register-reference and I/O formats, only one of the lower 12 bits is
set.
Instruction Type – Data Transfer
• Are responsible for moving data around inside the processor as well
as bringing in data or sending data out
• Examples: Store, load, exchange, move, set, push, pop
• Each Instruction should have:
• source and destination (memory, register, input/output port)
• amount of data
Machine Instruction
Instruction Type – Arithmetic
• Add, Subtract, Multiply, Divide for signed integer (+ floating point and
packed decimal)
– may involve data movement
• May include:
– Absolute (i.e |a|)
– Increment (i.e a++)
– Decrement (i.e a--)
– Negate (i.e -a)
Instruction Type – Logical
• Bitwise operations: AND, OR, NOT, XOR, CMP, SET
• Shifting and rotating functions, e.g.
– logical right shift for unpacking: send 8-bit character from
16-bit word
– arithmetic right shift: division and truncation for odd numbers
– arithmetic left shift: multiplication without overflow
Address Instruction
• Instructions are operations performed by the CPU. An instruction comprises
groups called fields. These fields include: The Operation code (Opcode) field
determines the process that needs to be performed. The Address field contains
the operand's location, i.e., register or memory location. The Mode field specifies
how the operand is located. Operands are entities operated upon by the
instruction. Addresses are the locations in the memory of specified data.
• Address instruction refers to the different ways computer instructions specify
locations (addresses) for operands (data) and results, typically categorised
as zero, one, two, or three-address instructions, depending on how many
memory/register locations are explicitly named within the instruction format.
These formats dictate CPU architecture (accumulator, general-purpose registers,
stack-based) and impact code size and complexity, with three-address
instructions often simplifying high-level logic but using more bits, and zero/one-
address formats being more compact but requiring more steps.
Instruction Cycle State Diagram
Machine Instruction
Elements of a Machine Instruction
• Each instruction must contain the information required by the processor for
execution.
• The steps involved in the instruction execution and, by implication, define the
elements of a machine instruction. These elements are as follows:
• 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.
• 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.
Types of Addressing Modes
Types of Addressing Modes
• Implicit (Implied): The operand's location (e.g., accumulator) is built into the instruction itself, requiring no
explicit address field.
• Immediate: The operand's value (a constant) is part of the instruction, not a memory address.
• Register Direct: The operand is directly in a specified CPU register.
• Register Indirect: The instruction contains a register that holds the memory address of the operand.
• Direct (Absolute): The instruction contains the actual, fixed memory address of the operand.
• Indirect: The instruction's address field points to another memory location, which then contains the actual
operand address (two memory accesses).
• Indexed: The effective address is calculated by adding a constant (offset) to the content of an index register.
• Base Register: Similar to indexed, but uses a base register plus an offset.
• Relative: Adds the instruction's address (or PC content) to a displacement to find the operand, useful for
loops.
• Stack: Operands are implicitly on the stack (e.g., PUSH, POP operations).
• Auto-Increment/Decrement: Automatically increments or decrements a register after or before using its
value as an address, common in array/string processing.
Immediate Addressing Mode
• The simplest form of addressing is immediate addressing, in which the
operand value is part of the instruction itself. It is used when the value is
known while writing the program.
• This mode can be used to define and use constants or set initial values of
variables. Typically, the number will be stored in two’s complement form;
the leftmost bit of the operand field is used as a sign bit. When the
operand is loaded into a data register, the sign bit is extended to the left to
the full data word size.
• Advantages
• 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.
Immediate Addressing Mode
Sign Bit
Direct Addressing Mode
The instruction contains the memory
address of the operand. The CPU
accesses the data directly from that
address.
Example: LOAD R1, 1000 - loads data
from memory address 1000 into register
R1.
Indirect Addressing Mode
The instruction contains the address of a
register or memory location that holds the
actual address of the operand. The CPU first
fetches this address, then accesses the
operand.
Example: LOAD R1, (R2) loads data from the
memory location whose address is in register
R2.
Register Addressing Mode
The operand is located in a CPU
register specified by the instruction.
The instruction specifies a register (R).
The CPU takes the operand directly
from register R.
Example: MOV A, B - operates
between registers A and B.
Register Indirect Addressing Mode
The register specified in the instruction
contains the memory address of the
operand. The instruction specifies a
register. This register holds the address (A).
The CPU fetches the operand from
memory location A.
Example: MOV A, [R1] - uses the content of
R1 as the memory address.
Displacement Addressing Mode
The operand’s effective address is calculated
by adding a constant value (displacement)
to the contents of one or more registers.
The instruction provides a base register (R)
and an address part (A). CPU adds the value
of R and A to get the effective operand
address. Operand is fetched from the
calculated address in memory.
Example: Used for arrays, accessing an
element at a position relative to a base.
Stack Addressing Mode
The operand is implicitly taken from the top
of the stack, without being mentioned in
the instruction. Operation is performed
using the value at the stack’s top (implied
by the instruction). No need for explicit
operand field; CPU refers to stack pointer
register by default.
Example: POP and PUSH operations.
Types of Address Instructions
• Zero Address – No address fields; operands are implicitly on a stack
(e.g., ADD in a stack machine).
• One Address – One address field; uses a single accumulator register
(e.g., ADD B).
• Two-Address – one specifies source/destination, the other source
(e.g., ADD A, B).
• Three address fields – specifies two source operands and one
destination (e.g., ADD R1, A, B).
CPU Organisation & Address Types
• Accumulator-based: Uses one-address instructions.
• Register-based (General Purpose): Often uses two or three-address
instructions, with operands in registers.
• Stack-based: Uses zero-address instructions for operations,
but PUSH/POP need addresses.
Key Differences Between Address Instructions
• Code Size: Three-address programs are often shorter in instruction count
but use more bits per instruction; zero/one-address use fewer bits per
instruction but more instructions overall.
• Flexibility: Three-address instructions offer more power by separating
sources and destinations.
• Implementation: Choice depends on hardware design, cost, and target
performance.
Three Address Instruction
Three-address instruction is a type that is
a machine-specific instruction. It is a
single opcode with three fields for
address. The address field serves to
indicate the destination, and two address
fields are provided for the source.
Example: X = (A - B)/(D*E)
Two-Address Instruction
Two-address instructions simplify the
instruction format by using one operand
as both source and destination, which
affects how data is manipulated and
stored during program execution.
Example: X = (A-B)/(D*E)
One Address Instruction
One Address Instruction – requires one
operand. This uses an implied
ACCUMULATOR (AC) register for data
manipulation. One operand is in the
accumulator, and the other is in a register
or memory location. Implied means that
the CPU already know that one operand is
in the accumulator (implying that an ALU
operation will be performed).