Back to the 2019 paper

Module 2: x86 Architecture, CPU Control, I/O, Memory System Design

20197m

Describe autoincrement and decrement addressing modes with proper examples.

Worked SolutionAI Assisted

Solution - Autoincrement and Autodecrement Addressing Modes

Both are Register Indirect with automatic update modes, useful for array/table traversal and stack operations.

1. Autoincrement Addressing Mode: (R)+(R)+ or [R+][R+]

  • Definition: Effective Address EA=[R]EA = [R] (content of register gives address). After operand is accessed, register is automatically incremented by size of operand (+1+1 for byte, +2+2 for 16-bit word, +4+4 for 32-bit).
  • Operation: EA←REA \leftarrow R; R←R+dR \leftarrow R + d (where dd = operand size).
  • Use: For traversing arrays/buffers in forward direction, popping from stack, reading sequential data.

Example (8086-like / PDP-11 style):
Suppose R1=1000HR_1 = 1000H, Memory[1000]= ABAB, Memory[1001]= CDCD (16-bit).
Instruction: MOV (R1)+, R2 ; or MOV @R1+, AC

  • Fetch operand from address 1000H into R2.
  • Then R1←1000H+2=1002HR_1 \leftarrow 1000H + 2 = 1002H (for word).
    Now R1R_1 points to next element automatically.

Array sum loop:

      MOV #ARRAY, R1   ; R1 -> start
      CLR  R3          ; sum=0
LOOP: ADD (R1)+, R3    ; add *R1 to sum, R1 moves to next
      DEC  R2          ; count
      BNE  LOOP

2. Autodecrement Addressing Mode: −(R)-(R) or −[R]-[R]

  • Definition: Register is first decremented by operand size, then its content is used as Effective Address. R←R−dR \leftarrow R - d; EA←REA \leftarrow R.
  • Use: For traversing arrays backward, pushing onto stack (stack grows downward).

Example:
Suppose R1=1002HR_1 = 1002H, SP=2000HSP = 2000H.
Instruction: MOV R2, -(R1) or PUSH R2 is MOV R2, -(SP)

  • First SP←2000H−2=1FFEHSP \leftarrow 2000H - 2 = 1FFEH
  • Then Memory[1FFEH1FFEH] ←R2\leftarrow R_2.
    So decrement-before-store prevents overwriting.

Array reverse traversal:

      MOV #ARRAY_END, R1  ; point beyond last element
LOOP: MOV -(R1), R2       ; R1-- first, then fetch

Combined Example - Stack:

  • PUSH A = MOV A, -(SP) (autodecrement)
  • POP A = MOV (SP)+, A (autoincrement)

Comparison Table:

Feature Autoincrement (R)+(R)+ Autodecrement −(R)-(R)
Order Use then increment Decrement then use
Pointer moves Forward Backward
For Stack POP PUSH
Initial R points To current operand To next free location

Both modes eliminate extra ADD/SUB instructions, improving code density and loop efficiency.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.