1 of 21

1

Addressing Modes

krraju.in

2 of 21

What you’ll learn

  • Different ways of operand access for an instruction execution.
  • How to choose an addressing mode.

2

Central Processing Unit: Introduction, General Register Organization, Stack Organization, Instruction Formats, Addressing Modes, Data Transfer and Manipulation, Program Control, Reduced Instruction Set Computer (RISC)

Unit-3

krraju.in

3 of 21

Byte Ordering

3

The most significant byte of the data is stored in the low addressed byte followed by remaining bytes in higher addressed locations.

The least significant byte of the data is stored in the low addressed byte followed by remaining bytes in higher addressed locations.

Storing a multiple byte data element in a byte-addressable architecture.

krraju.in

4 of 21

Word Alignment

Storage of different data types might require different multiples of bytes. This results in the storage that is not in exact multiples of word size.

  • Aligned access: The address starts from word boundary to access a multi-byte word from memory.
  • Unaligned access: The address starts from any arbitrary byte address.

4

krraju.in

5 of 21

Addressing Mode

Most instructions have operands, specifying where the operands are (i.e., their addresses) is called addressing.

Addressing mode refers to the way in which the operand of an instruction is chosen during program execution.

  • Determines how processors access and manipulate data within a system's memory or registers
  • The instruction may have more than one address field.
    • Each address field may be associated with its own addressing mode.

5

Opcode

Mode

Operand Address

Instruction with mode field

krraju.in

6 of 21

Why Addressing Mode is important?

  • To give programming versatility to the user
  • To refer to a large range of locations with reduced number of bits in the address field of the instruction.

Enables efficient memory utilization, operand access, and code optimization, which ultimately impacts the system's overall performance.

6

  • Pointers to memory
  • Counters for loop control
  • Indexing of data
  • Program relocation
  • Access to complex data structures such as tables, vectors, arrays and lists.

Trade off

  • Addressing range and flexibility
  • Complexity of the effective address calculation.

krraju.in

7 of 21

Implicit/Inherent/Implied Mode

  • Operands are specified implicitly in the definition of the instruction.
  • Typical usage
    • Stack operations (operands are implied to be on the top of the stack)
      • PUSH, POP,...
    • CMA (complement Acc)

7

Opcode

Instruction

krraju.in

8 of 21

Immediate/Literal Mode

  • It allows a reference to a constant that is known at assembly time.
  • The operand is contained within the instruction itself.

Advantage:

  • Data is constant at runtime.
  • No additional memory references are required after the fetch of the instruction itself.

Disadvantage:

  • Size of the operand (thus its range of values) is limited.

Typical usage: Constant operand

    • MVI A 05

8

Opcode

Instruction

Operand

krraju.in

9 of 21

Direct/Absolute Mode

  • Instruction contains the address of the operand.
    • No calculations are required for an effective address.
  • Fast addressing: Only one memory access is required to fetch the operand.
  • Address range limited by the width of the address field.
  • Rarely used
  • Operand is limited to the size of one word

9

Opcode

Instruction

Address

Memory

Operand

krraju.in

10 of 21

Direct/Absolute Mode contd..

  • It is used to access a pointer variable whose address is known at assembly time.
  • Address is a constant at run time but data itself can be changed during program execution.
  • Typical usage
    • Global variable
    • MOVE MemAdr,D0 (68000), LDA 5400 (8085)
    • Some machines use variations of direct addressing:
      • Direct and extended addressing on the 68HC11 – 8 and 16 bit addresses.
    • LOAD R1, 100: Loads the content of memory address 100 to register R1
    • AC = AC + [X]: Adds the operand stored at address X with the operand stored in the accumulator
    • Add R2, A: Memory location A content is to be added to the register R2 content

10

krraju.in

11 of 21

Indirect Mode

  • It is used to access a pointer variable whose address is known at compile time.
  • The address field in the instruction specifies a memory location which contains the address of the data.
  • Two memory accesses are required.
    • The first to fetch the effective address
    • The second to fetch the operand itself

11

Opcode

Instruction

Address

Memory

Operand

Address

krraju.in

12 of 21

Indirect Mode Contd..

  • Range of effective addresses is equal to 2n, where n is the width of the memory data word.
  • Number of locations that can be used to hold the effective address is constrained to 2k, where k is the width of the instruction’s address field
  • Typical usage:
    • Accessing a value through its pointer.

12

krraju.in

13 of 21

Register Direct Mode

  • It is like direct mode, but address field specifies a register location.
  • Typical usage:
    • Temporary variable; R(t) ⟵ R(a)
  • Faster access to data.
  • Smaller address field in the instruction since the number of registers are less.

13

Opcode

Instruction

Reg.

Registers

Operand

krraju.in

14 of 21

Register Indirect Mode

  • It is like indirect, but address field specifies a register that contains the effective address.
  • It is used when the address of the operand is not known until run time.
  • Typical usage:
    • Pointers to structures; R(t) ⟵ M(R(a))

14

Opcode

Instruction

Reg.

Registers

Address

Memory

Operand

krraju.in

15 of 21

Displacement Addressing

  • Two address fields in the instruction are used.
    • One is an explicit address reference and the other is a register reference. EA=A+(R)

15

Opcode

Instruction

Reg.

Registers

Address

Memory

Operand

Address Offset

krraju.in

16 of 21

Relative Address Mode

  • Address is added to the program counter contents to cause a branch operation in fetching the next instruction.
  • Typical usage:
    • Instructions or values stored within the program.

16

Opcode

Instruction

Program Counter

Address

Memory

Operand

Address Offset

krraju.in

17 of 21

Base Register Addressing Mode

  • Address is a displacement (offset) added to the contents of the referenced base register to form the EA.
  • Typical usage:
    • Arrays and structures.
    • Used by programmers and operating system to identify the start of user areas, segments, etc. and provide accesses within them.

17

Opcode

Instruction

Base Register

Address

Memory

Operand

Address Offset

krraju.in

18 of 21

Indexed Addressing Mode

  • Address field is added to the referenced index register that contains the displacement (offset) value to form EA.
  • Typical usage:
    • Indexing is used within programs for accessing data structures (arrays and structures).

18

Opcode

Instruction

Index Register

Address Offset

Memory

Operand

Address

krraju.in

19 of 21

Auto Increment/Decrement Mode

Auto increment

    • R(t) ⟵ M(R(a)); R(a) ⟵ R(a)+1
  • Typical usage:
    • Sequential access or stack pop.

Auto decrement

    • R(a) ⟵ R(a)-1; R(t) ⟵ M(R(a))
  • Typical usage:
    • Sequential access or stack push.

19

krraju.in

20 of 21

Recap

20

krraju.in

21 of 21

Video Links

21

krraju.in