Docsity

ADresseing modes explained, Lecture notes of Computer Architecture and Organization

Toggle sidebar
bg1
Page 1 From 9
By: Baraa Salout
Addressing Modes
Addressing modes are an aspect of the instruction set architecture in most central processing
unit (CPU) designs. The various addressing modes that are defined in a given instruction set
architecture define how machine language instructions in that architecture identify the
operand(s) of each instruction. An addressing mode specifies how to calculate the effective
memory address of an operand by using information held in registers and/or constants
contained within a machine instruction or elsewhere.
Addressing Modes
Applications
Immediate Addressing Mode
To initialize registers to a constant value
Direct Addressing Mode
and
Register Direct Addressing Mode
To access static data
To implement variables
Indirect Addressing Mode
and
Register Indirect Addressing Mode
To implement pointers because pointers are memory
locations that store the address of another variable
To pass array as a parameter because array name is
the base address and pointer is needed to point the
address
Relative Addressing Mode
For program relocation at run time i.e. for position
independent code
To change the normal sequence of execution of
instructions
For branch type instructions since it directly updates
the program counter
Index Addressing Mode
For array implementation or array addressing
For records implementation
Base Register Addressing Mode
For writing relocatable code i.e. for relocation of
program in memory even at run time
For handling recursive procedures
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download ADresseing modes explained and more Lecture notes Computer Architecture and Organization in PDF only on Docsity!

Page 1 From 9

Addressing Modes

Addressing modes are an aspect of the instruction set architecture in most central processing unit (CPU) designs. The various addressing modes that are defined in a given instruction set architecture define how machine language instructions in that architecture identify the operand(s) of each instruction. An addressing mode specifies how to calculate the effective memory address of an operand by using information held in registers and/or constants contained within a machine instruction or elsewhere. Addressing Modes Applications Immediate Addressing Mode To initialize registers to a constant value Direct Addressing Mode and Register Direct Addressing Mode To access static data To implement variables Indirect Addressing Mode and Register Indirect Addressing Mode To implement pointers because pointers are memory locations that store the address of another variable To pass array as a parameter because array name is the base address and pointer is needed to point the address Relative Addressing Mode For program relocation at run time i.e. for position independent code To change the normal sequence of execution of instructions For branch type instructions since it directly updates the program counter Index Addressing Mode For array implementation or array addressing For records implementation Base Register Addressing Mode For writing relocatable code i.e. for relocation of program in memory even at run time For handling recursive procedures

Page 2 From 9

1. Immediate Addressing

In this mode, the operand is specified in the instruction itself. An immediate mode instruction has an operand field rather than the address field. Examples -

  • ADD 10 will increment the value stored in the accumulator by 10.
  • MOV R #20 initializes register R to a constant value 20.

2. Direct Addressing Mode

In this mode, effective address of operand is present in instruction itself. o Single memory reference to access data. o No additional calculations to find the effective address of the operand. Example-

  • ADD X will increment the value stored in the accumulator by the value stored at memory location X. AC โ† AC + [X]

3. Indirect Addressing Mode

In this, the address field of instruction gives the address where the effective address is stored in memory. This slows down the execution, as this includes multiple memory lookups to find the operand. Example-

  • ADD X will increment the value stored in the accumulator by the value stored at memory location specified by X. AC โ† AC + [[X]]

Page 4 From 9

NOTE-

It is interesting to note-

  • This addressing mode is similar to indirect addressing mode.
  • The only difference is address field of the instruction refers to a CPU register

6. Displacement Addressing Mode

In this the contents of the indexed register is added to the Address part of the instruction, to obtain the effective address of operand. EA = A + (R), In this the address field holds two values, A(which is the base value) and R(that holds the displacement), or vice versa.

I. Relative Addressing Mode

In this addressing mode, Effective address of the operand is obtained by adding the content of program counter with the address part of the instruction. EA = A + (PC), where EA is effective address and PC is program counter. The operand is A cells away from the current cell (the one pointed to by PC)

II. Base Register Addressing Mode

This can be defined as EA = A + (R), where A is displacement and R holds pointer to base address.

III. Indexing

A= main memory address R=displacement from that address EA = A + content(R) A lenght comparibly large than base register addressing

i. Auto indexing

index register, that is R displacement register, are used in iterative task so need to increment and decrement to address arrays or memory automatically done part of same instruction cycle EA = A + content(R) R = R + 1

Page 5 From 9

ii. Post indexing

indirect addressing + indexing EA = content of A + content of R

iii. Preindexing

EA = contents of (A + content (R))

7. Stack Addressing Mode

In this mode, operand is at the top of the stack. For example: ADD, this instruction will POP top two items from the stack, add them, and will then PUSH the result to the top of the stack. Example - ADD

  • This instruction simply pops out two symbols contained at the top of the stack.
  • The addition of those two operands is performed.
  • The result so obtained after addition is pushed again at the top of the stack.

Page 7 From 9 ADD Rd, 1000

  • This instruction uses immediate addressing mode.
  • The instruction is interpreted as Rd โ† [Rd] + 1000.
  • Value of the operand = [Rd] + 1000 = 1 + 1000 = 1001.
  • Thus, value = 1001 is moved to the register Rd. STORE 0(Rd), 20
  • This instruction uses displacement addressing mode.
  • The instruction is interpreted as 0 + [Rd] โ† 20.
  • Value of the destination address = 0 + [Rd] = 0 + 1001 = 1001.
  • Thus, value = 20 is moved to the memory location 1001. Thus,
  • After the program execution is completed, memory location 1001 has value 20.
  • Memory location 1001 has value 20

Page 8 From 9 Q 2 )

Consider the following memory values and a one-address machine with an

accumulator, what values do the following instructions load into accumulator?

  • Word 20 contains 40
  • Word 30 contains 50
  • Word 40 contains 60
  • Word 50 contains 70 Instructions are-
  1. Load immediate 20
  2. Load direct 20
  3. Load indirect 20
  4. Load immediate 30
  5. Load direct 30
  6. Load indirect 30 Solution- Load immediate 20
  • This instruction uses immediate addressing mode.
  • The instruction is interpreted as Accumulator โ† 20.
  • Thus, value 20 is loaded into the accumulator. Load direct 20
  • This instruction uses direct addressing mode.
  • The instruction is interpreted as Accumulator โ† [20].
  • It is given that word 20 contains 40.
  • Thus, value 40 is loaded into the accumulator