The types of addressing modes :
The most common addressing modes :
All computer architectures provide more than one of these addressing modes.The question arises as to how the control unit can determine which addressing mode is being used in a particular instruction.Several approaches are used.Often,
- Immediate Addressing mode
- Direct addressing mode
- Indirect addressing mode
- Register addressing mode
- Register insirect addressing mode
- Displacement addressing mode
- Stack addressing mode
- Different opcodes will use different addressing modes.Also
- One or more bits in the instruction format can be used as a mode field.The value of the mode field determines which addressing mode is to be used.
Immediate Addressing Modes :
The simplest form of addressing is immediate addressing, in which the operand is actually present in the instruction :
OPERAND = A
This mode can be used to define and use constants or set initial calues of variables.
- The advantages of immediate addressing is that no memory reference other than the instruction fetch is required to obtain the operand
- The disadvantages is that the size of the number is restricted to the size of the address field, which, in most instruction sets, is small compared with the world length.
Direct Addressing Modes :
A very simple form of addressing is direct addressing.In direct addressing mode, effective address of the operand is given in the address field of the instruction.
It requires one memory reference to read the operand from the given location and provides only a limited address space.length of the address field is usually less than the word length.
The fetching of data from the memory location in case of direct addressing mode is shown :
Indirect Addressing Modes :
Indirect addressing mode, the address field of the instruction refers to the address of a word in memory, which in turn contains the full length address of the operand.With direct addressing, the full length of the address field is usually less than the word length, thus limiting the address range.One solution is to have the address field refer to the address of the operand.This is known as indirect addressing :
EA = (A)
- The advantage of this mode is that for the word length of N, an address space of 2N can be addressed
- The disadvantage is that instruction execution requires two memory reference to fetch the operand multilevel.
The exact memory location of the operand in case of indirect addressing mode
Register Addressing Mode :
Register Addressing mode is similar to direct addressing.The only difference is that the address field of the instruction refers to a register rather than a memory location 3 or 4 bits are used as address field to reference 8 to 16 generate purpose registers.
- The advantages of register addressing are small address field is needed in the instruction
- The disadvantages of register addressing is that the address space is very limited
The exact register location of the operand in case of Register addressing mode is shown :
Register Indirect Addressing Mode :
This mode is similar to indirect addressing.The address field of the instruction refers to a register.The register contains the effective address of the operand.Thi mode uses one memory reference to obtain the operand.The address space is limited to the width of the registers available to store the effective address.
EA = (R)
Displacement Addressing Mode :
A very powerful mode of addressing combines the capabilities of direct addressing and register indirect addressing, which is broadly categorized as displacement addressing :
EA = A + (R)
Displacement addressing requires that the instruction have two address fields, as least one of which is explicit.The value contained in one address field (value = A) is used directly.The other address field, or an implicit reference based on opcode, refers to a register whose contents are added to A to produce the effective address.The general format of Displacement Addressing is Shown :
In displacment addressing mode there are 3 types of addressing mode.They are :
- Relative addressing mode
- Base register addressing
- Indexing addressing
Relative Addressing Mode :
For relative addressing, the implicity referenced register is the program counter(PC).That is, the current instruction address is added to the address field to produce the EA.Thus, the effective address is a displacement relative to the address of the instruction.
Base register Addressing Modes :
The reference register conatins a memory address, and the address field contains a displacement from that address.The register reference may be explicit or implicit.
In some implementation, 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.
Indexing Addressing Modes :
The address field reference a main memory address, and the refernce register contains positive displacement from that address.In this case also the register reference is sometimes explicit an sometimes implicit.
Generally index register are used for iterative tasks, it is typical that there is a need to increment or decrement the index register after each reference to it.Because this is such a common operation, some system will automatically do this as part of the same instruction cycle.
This is known as auto-indexing.We may get two types of auto-indexing :
- One is auto incrementing and the other one is
- Auto decrementing
If certain registers are devoted exclusively to indexing, then auto indexing can be invoked implicitly and automatically.If general purpose register are used, the auto index operation may need to be signed by a bit in the instruction.
Auto-indexing using increment can be depicted as follows :
EA = A + (R)
R = (R) + 1
Stack Addressing Modes :
A stack is a linear array or list of locations.It is sometimes referred to as a pushdown list or last in fast out queue.A stack is a reserved block of locations.Items are appended to the top of the stack so that, at any given time, 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.
The stack mode of addressing is a form of implied addressing.The machine isntructions need not include a memory reference but implicitly operate on the top of the stack.
The general Structure of the IAS Computer :
- A main memory, which stores both data and instructions
- An arithmetic and logic unit(ALU) capable of operating on binary data
- A control unit, which interprets the instructions in memory and causes them to be executed
- Input and Output(I/O) equipment operated by the control unit
The IAS Memory Format :
The memory of the IAS consists of 1000 storage locations, called words, of 40 binary digits (bits) each
- Both data and instructions are stored there
- Numbers are represented in binary form, and each instruction is a binary code
- Each number is represented by a sign bit and a 39 bit value
- A word may also conatin two 20-bit instructions, with each instruction consisting of an 8-bit operation code (opcode) specifying in the operation to be performed and a 12-bit address designating one of the words in memory (numbered from 0 to 999)
The Expanded Structure of the IAS Computer function :
Memory buffer register(MBR) :Contains a word to be stored in memory or sent to the I/O unit, or is used to receive a word from memory or from the I/O unit.
Memory address register(MAR) :Specifies the address in memory of the word to be written from or read into the MBR
Instruction register(IR) :Contains the 8-bit opcode instruction being executed
Instruction buffer register(IBR) :Employed to hold temthe right hand instruction from a word in memory.
Program Counter(PC) :Contains the address of the next instruction pair to be fetched from memory.
Accumulator(AC) and Multiplier Quotient(MQ) :Employed to hold temporarily operands and results of ALU operations.
Example :The result of multiplying two 40-bit numbers is an 80-bit number; the most significant 40bits are stored inthe AC and the least significant in the MQ.
Instruction set :
The instruction of a CPU is determined by the instructions it executes, referred to as machine isntructions or computer instructions.
Function of Instruction Set :
Operation Code :Specifies the operation to be performed.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 CPU where to fetch the next instruction after the instruction after the execution of this instruction is complete