We already know Why we need Addressing mode
Types of Addressing mode:-
1. Implied Mode:-
It is also called an Implicit mode. Here the address is given in the instruction Itself. ex. INCA. it means to increment the content of A. A is an accumulator.
2. Immediate mode:
- The direct value of the operand is given directly with the instruction. ex. Add 10. here there is no need for further calculation.
- This mode deals with constant.
3. Register Direct Mode:-
Here we put the operand in a special box and in the instruction we give that box number. That special box is called a register.Ex.
Add R1, it means Add the content of Accumulator with the content present in box R1 and store the end value in the accumulator.
AC <-- AC + (R1)
4.Register Indirect Mode:-
We put the operand in a safe house and keep the address of that safe house in our special box and In instruction, we give that special box serial number.
Here safe house means some memory address and the special box is our register. Ex:
Add R1, it means
AC <-- AC + M [(R1)]
from R1 we take the address of memory address and then we go to that memory and fetch the operand.
5. Direct Mode:
- This is also called as Absolute mode.
- It is used with variables.
We put our operand in a safe house and In instruction, we directly give that safe house address. Ex.
Add X, it means
AC <-- AC + M[X]
You go to memory location X and fetch the opcode and add it with the content present in the accumulator and store the end result back to the accumulator.
6. Indirect Mode:
- It is used to implement pointer.
- Use to implement parameter passing.
Story: Queen's diamond has been stolen and James bond has been assigned a task to search the diamond. James Bond has been provided an address AD52 by Felix Leiter.
When James bond reaches to AD52 he got an envelope that contains some address E96. When he reached E96 finally he got queen's diamond.
This is the concept of Indirect Addressing Mode.
Here Address of effective address is given with instructions.
Example: Add X it means
A <-- A + M [ M[X] ]
7. Relative addressing mode:
Use to implement branch instruction.
Uses a program counter for implementation.
Example: A relative address might be A+15, A is the base address and 15 the distance (called the offset).
let's assume the current address is 400 and you have to go to a branch of -20 so what is destination address?
The time at which address 400 is being executed, the program counter will contain 401
So -20 displacement is = 401 + (-20) =381
8.Indexed Addressing Mode:-
- It is useful when we are trying to access an element in the array.
- You are provided the base address and you have to calculate the designated address.