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

Addressing Mode

Addressing modes and its numericals
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Addressing Mode

Addressing modes and its numericals
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Addressing mode(Introduction )

Instruction Format

• The operation (opcode ) field of an instruction specifies the operation to be


performed . This operation will be executed on some data (operand).
• Address field specifies the computer registers or the main memory , where
data /operand is stored .
• The way the operand are chosen during the program execution is dependent on
the addressing mode of the instruction.
• Address field: contains the information needed to determine the location of the
operands and result of an operation .
• Addressing mode: specifies how to interpret the information with in this address
field , how to compute the actual or effective address of the data needed.
 The purpose of using addressing modes is:
 To give the programming versatility to the user .
 Pointers to memory ,counters for loop, indexing of data , program relocation, etc.
 To reduce the number of bits in addressing field of instruction.

Important points to remember :


 Instruction cycle
 Fetch the instruction from memory , PCPC+1
 Decode the instruction
 Execute the instruction
 Program Counter
 PC keeps track of the instruction in the stored memory .
 PC holds the address of the next instruction to be executed .
 PC is incremented each time an instruction is fetched from the memory.

 Effective address (EA) : EA is the actual address of the operand , where it is actually stored.
Types of Addressing modes :
1. Implied /Implicit Addressing mode
2. Immediate Addressing Mode
3. Direct Addressing Mode
4. Indirect Addressing Mode
5. Register Direct Addressing Mode
6. Register Indirect Addressing Mode
7. Indexed Addressing Mode
8. Relative Addressing Mode
1. Implied /Implicit Addressing mode:

 Operands are specified implicitly in the definition of instruction.

 Examples
 CMA :Complement Accumulator
 Operand in Ac is implied in the definition of the instruction

 CLA : Clear Accumulator


• Operand in AC is implied in the definition of the instruction

 PUSH : Stack Push


 Operand is implied to be on top of the Stack(TOS).
2. Immediate Addressing Mode

 Operand is specified in instruction itself.


 An immediate mode instruction has an operand field rather than the address field.
 Operand field contain the actual operand
 Operand = Address

 Example : LOAD #7 //AC7


ADD # 5 // AC  AC + 5
3. Direct Addressing Mode :
 The Operand resides in memory and its address is given directly by the address field of
instruction.
 Address field of instruction contains the effective address EA (or actual address )of
operand
 EA= A Effective Address is equal to the address field (A)

 Example : ADD A //AC  AC + M[A]


LOAD B // AC  M[B]
 It is also called as absolute addressing mode
 Advantages :
• Simple
• Single(One)memory reference to access data
• No additional calculation st to work out effective address
 Disadvantages :
 Address space is limited to the size of the address field
Direct Addressing Mode :
4. Indirect Addressing Mode:

 Address field of instruction specifies the address where the effective


address of operand is stored in the memory.
 EA =(A) or EA =@A look in A, find address (A) and look there for operand

 Example : ADD(A) or ADD@A // AC AC + M{M[A]}


 Advantages
• Larger address space is possible
• where n = word length.
 Disadvantages :
 Multiple (two) memory reference to find the operand
 Hence slower .
Indirect Addressing Mode:
5. Register Direct Addressing Mode
 Operand is stored in the register ( Register resides with in the CPU)
 Address field of the instruction refers to a CPU register that contains the
operand .
 EA=
 A K- bit field can specify any one
 Example MOV R1, R2 // R! R2
 No reference to memory is required to fetch the operand .
 Advantages:
 Due to limited number of registers, very small address field
 Shorter instructions
 NO memory reference (Access)
 Very fast execution
 Disadvantages :
 Very limited address space
 Using multiple registers helps performance but it complicates the instructions.
Register Direct Addressing Mode
6. Register Indirect Addressing Mode
 The Address field of instruction specifies the register that contains the
effective address of operand. The operand is in the memory.
 The register contains the effective address of operand rather than the operand
itself.
 EA = (
 Examples : ADD (R1),R2 //M[R1] M[R1] + R2

 Advantages
• Address field of instruction uses fewer bits to select a memory address
• Large address space :
• One fewer memory access than indirect addressing
 Disadvantages
 Extra memory reference
Register Indirect Addressing Mode
7. Indexed Addressing Mode
 Register = Index register
 The content of index Register is added to the address part of the instruction to obtain the
effective address of operand .
Effective address = Content of XR + Address part of instruction
 EA = A + (XR) or EA = A+ (
o A contains a constant value in the instruction
o XR/
 Index register used here is either a special CPU register (XR) provided for this purpose or
commonly , it may be anyone of a set of general register (
 Example : ADD R1,20(R2) // R1  R1 + M {20+R1}
ADD R1, 100(XR) // R! R1 + M{100+ XR}
Indexed Addressing Mode
8. Relative Addressing Mode
 Register = Program Counter (PC) {PC keeps the address of the next register}
 The content of PC is added to the address part of the instruction to obtain the
effective address of operand .
Effective address = Content of PC + Address part of instruction
 EA =(PC)+ A i.e. the operand is A bytes away from current location pointed
by PC .
 Example
LOAD $A or LOAD A(PC) // AC M[PC + A]
 Address location is relative to “PC”, this is called Relative Mode.
Relative Addressing Mode
Example Q. For each possible mode we calculate the effective
address and the operand that must be loaded into AC.

PC 200
Address Memory • The two word instruction at address 200 and 201 is
R1 400 “load to AC”instruction with an address field equal to
200 Load to AC Mode
XR 100 500.
201 Address = 500
AC 202 Next Instruction • The first word of the instruction specifies the
operation code and mode , and the second word
PC = Program Counter specifies the address part.
399 450
R1 = Register
400 700 • PC has the value 200 , for fetching this instruction .
XR = Index Register
AC = Accumulator The content of processor register R1 is 400 , and the
500 800 content of an index register XR is 100.

• AC receives the operand after the instruction is


600 900
executed .

702 325 • The mode field of the instruction can specify any one
of a number of modes.
800 300
Example
1. Immediate Addressing Mode
• (Operand value in address field )
PC 200
Address Memory
R1 400
200 Load to AC Mode
• As instruction contains immediate number 500.
XR 100 • It is stored as address 201.
201 Address = 500
AC 202 Next Instruction
Effective Address = 201
PC = Program Counter 399 450 Operand = 500
R1 = Register
400 650
XR = Index Register
AC = Accumulator AC 500
500 800

600 900

702 325

800 310
Example
2. Direct Addressing Mode ( Address field contains the effective address)

Address Memory • Instruction contains the address 500.


PC 200 200 Load to AC Mode • So effective address of operand is 500.
201 Address = 500 • The data stored at 500 is 800.
R1 400
202 Next Instruction
XR 100
Effective Address = 500
399 450 Operand = 800
AC 400 650
AC 800
500 800

600 900

702 325

800 310
Example
3. Indirect Addressing Mode (Address field specifies the address where the effective address of operand is
stored in memory)
Address Memory • Instruction contains the address 500.
PC 200 200 Load to AC Mode • Address at 500 is 800.
• So effective address of operand is 800.
201 Address = 500
R1 400 • The data stored at 800 is 300.
202 Next Instruction
Effective Address = 800
XR 100
Operand = 300
399 450
AC 400 650
AC 300

500 800

600 900

702 325

800 310
Example
4. Register Addressing Mode ( Register contains operand )
PC 200
Address Memory
R1 400
200 Load to AC Mode • The operand is in R1 and 400 is loaded in AC
XR 100 • AC = 400
201 Address = 500
AC • There is no effective address in this case .
202 Next Instruction

Effective Address = Nil


PC = Program Counter 450
399 Operand = 400
R1 = Register
400 650
XR = Index Register
AC = Accumulator AC 400
500 800

600 900

702 325

800 310
Example
5. Register Indirect Addressing Mode (Register contains effective address of operand )
PC 200
Address Memory
R1 400
200 Load to AC Mode • Register R1 contains 400.
XR 100 • So effective address of operand is 400.
201 Address = 500
AC • The data stored at 400 is 650.
202 Next Instruction

PC = Program Counter 399 450 Effective Address = 400


R1 = Register Operand = 650
400 650
XR = Index Register
AC = Accumulator AC 650
500 800

600 900

702 325

800 310
Example
6. Relative Addressing Mode ( PC is added to address part )
Address Memory
PC 200 Load to AC Mode
• PC = 200.
200
• Offset = 500.
201 Address = 500
R1 400 • Instruction is of 2 bytes.
202 Next Instruction • So effective address = PC + 2 + offset = 200 + 500 +2 =
XR 100 702 .
399 450 • The data stored at 702 is 325.
AC 400 650

Effective Address = 702


500 800 Operand = 325

600 900
AC 325

702 325

800 310
Example
7. Index Addressing Mode (Index Register is added to address part)
Address Memory
PC 200 Load to AC Mode
• XR = 100.
200
• Base = 500.
201 Address = 500
R1 400 • So effective address = Base + XR = 500 + 100 = 600 .
202 Next Instruction • The data stored at 600 is 900.
XR 100
399 450
AC 400 650 Effective Address = 600
Operand = 900
500 800
AC 900

600 900

702 325

800 310

You might also like