addressing modes
DESCRIPTION
details about addressing modeTRANSCRIPT
![Page 1: Addressing Modes](https://reader035.vdocument.in/reader035/viewer/2022071807/55cf9339550346f57b9ce2e8/html5/thumbnails/1.jpg)
Addressing modes
Page 1 of 5
Addressing Modes
• Immediate • Direct • Indirect • Register • Register Indirect • Displacement (Indexed) • Stack Immediate Addressing
• Operand is part of instruction • Operand = address field • The machine code for MOV CX,7 is B9 07 00
CX CH: 00 CL: 07 The LSB of the operand field is used as sign bit. When the operand is loaded into a data register, the sign bit is extended to the left to the full data word size.
• Some additional examples of immediate addressing: MOV AL,20 ; put 20 decimal into AL ADD BH,20H ; add 20 hexadecimal to BH
SHL DX,1 ; shift DX left one bit AND AH,40H ; and AH with 40 hexadecimal SUB EAX,1 ; subtract 1 from EAX
• No memory reference to fetch data (thus saving 1 memory cycle in the
instruction cycle) • Fast • Limited range (size of the number is restricted to the size of address field)
Immediate Addressing Diagram
Instruction
Opcode Operand
![Page 2: Addressing Modes](https://reader035.vdocument.in/reader035/viewer/2022071807/55cf9339550346f57b9ce2e8/html5/thumbnails/2.jpg)
Addressing modes
Page 2 of 5
Direct Addressing
• Address field contains address of operand • Effective address (EA) = address field (A) • e.g. ADD A
—Add contents of cell A to accumulator
—Look in memory at address A for operand • Single memory reference to access data • No additional calculations to work out effective address Limited address space
Direct Addressing Diagram
Instruction
Opcode Address A
Memory
Operand
Indirect Addressing
• Memory cell pointed to by address field contains the
address of (pointer to) the operand • EA = (A)
—Look in A, find address (A) and look there for operand
• e.g. ADD (A) —Add contents of cell pointed to by contents of A to accumulator
![Page 3: Addressing Modes](https://reader035.vdocument.in/reader035/viewer/2022071807/55cf9339550346f57b9ce2e8/html5/thumbnails/3.jpg)
Addressing modes
Page 3 of 5
• Large address space • 2n where n = word length • May be nested, multilevel, cascaded
—e.g. EA = (((A)))
– Draw the diagram yourself • Multiple memory accesses to find operand • Hence slower
Indirect Addressing Diagram
Instruction
Opcode Address A
Memory
Pointer to operand
Operand
Register Addressing
• Operand is held in register named in address filed • EA = R • Limited number of registers • Very small address field needed
—Shorter instructions —Faster instruction fetch
• No memory access • Very fast execution • Very limited address space • Multiple registers helps performance
—Requires good assembly programming or compiler writing —C programming
– register int a;
• C.f. Direct addressing
![Page 4: Addressing Modes](https://reader035.vdocument.in/reader035/viewer/2022071807/55cf9339550346f57b9ce2e8/html5/thumbnails/4.jpg)
Addressing modes
Page 4 of 5
Register Addressing Diagram
Instruction
Opcode Register address R
Registers
Operand
Register Indirect Addressing
• C.f. indirect addressing • EA = (R) • Operand is in memory cell pointed to by
contents of register R
• Large address space (2n)
• One fewer memory access than indirect
addressing
Register Indirect Addressing Diagram
Instruction
Opcode Register address R
Memory
Registers
Pointer to Operand
Operand
![Page 5: Addressing Modes](https://reader035.vdocument.in/reader035/viewer/2022071807/55cf9339550346f57b9ce2e8/html5/thumbnails/5.jpg)
Addressing modes
Page 5 of 5
Displacement Addressing
• EA = A + (R) • Address field hold two values
—A = base value —R = register that holds displacement —or vice versa
Displacement Addressing Diagram
Instruction
Opcode Register R Address A
Memory
Registers
Stack Addressing
• Operand is (implicitly) on top of stack • e.g.
—ADD Pop top two items from stack and add
Operand
Pointer to Operand