You are on page 1of 51

Addressing modes

•Addressing modes is the way of representing the


location of an operand
•Three types
•Data-Addressing Modes
8086 through 80286: register, immediate, direct, register
indirect, base-plus-index, register relative,and base relative-plus-
index
80386 and above: scaled-index
MOV( Move data) instruction –moves byte, word or double word
•Program Memory-Addressing Modes
CALL and JUMP instructions
program relative, direct, and indirect
•Stack Memory-Addressing Modes
PUSH and POP instructions
Data Addressing Mode
MOV (move data) instruction: transfer bytes/words/
doublewords of data between registers, or
between register and memory
– MOVS: memory-to-memory transfer for strings
• opcode (operation code): MOV
• operands: AX and BX
8086-P4 Data-addressing Modes
1. Register Addressing
• Transfer a copy of a byte or word or double word from the source
register or memory location to the destination register or memory
location.
• Eg. MOV CX,DX MOV ECX,EDX
• Most common form
• Instructions must use registers of same size
• None of the MOV instruction effect the flag bits.
• Segment to segment register move is not allowed
• Changing CS register with a mov instruction is not allowed.
• While using mov instruction the source register content do not
change but destination changes.
• The content of destination changes for all instruction except the
CMP and TEST instructions
Examples of register addressing
Operation of MOV BX,CX
instruction
A sequence of assembled
instructions
2. Immediate Addressing
• Transfer the source-immediate byte or word or double word of data in to the
destination register.
• Eg. MOV CX,22H MOV ECX,1233456H
• Immediate implies the data immediately follow the hexadecimal opcode in the
memory
• In some assemblers # symbol precedes immediate data
• The letter H is appended with hexa decimal data
Examples of immediate addressing
Programming
• Assemblers
• Intel ASM
• Microsoft MSAM – MACRO assembler
• Borland TASM – Turbo assembler
Simple Program
Program Explanation
• .MODEL Tiny - direct the assembler to assemble the program in to
a single code segment.
• .code- start of the code segment
• .startup - indicates the starting instruction in the program
• .exit- causes the program to exit to dos
• END – indicates the end of the program.
• Tiny program always assembles as a command (.com) program.
• The program places 0000H into the 16 bit registers AX, BX.CX
(immediate addressing), then copy the contents of AX to SI , DI and
BP (register addressing).
• Each statement have 4 parts
1) label – used to store a symbolic name for memory location
2) opcode – holds the instruction
3) operand – contains information used by opcode (can have
beween 0 and 3 operands)
4) comment – comment about the instruction, alwaya begin with
a semicolon
• Assembler genetaes a .lst file which includes machine code,
address and the program
3. Direct Data Addressing
• Moves a byte or word or double word between a memory location and register.
• Does not support memory to memory transfer except for MOVS instruction
• Eg mov cx, list
• Two basic forms
1) Direct addressing – applies to a mov between memory location and AL,AX.EAX
2) Displacement addressing – applies almost any instruction.
• The sddress is formed by adding the displacement to the DS or an alternate segment
address.
• Direct addressing
• 3 byte long instruction
• Eg MOV AL,DATA
• DTA is a symbolic name , actual location is 1234H
• The effective address is formed by adding 1234 and segment
address.
• Displacement addressing
• 4 byte long instruction
• In 386 and above it can be upto 7 bytes long.
Program
Program explanation
• MODEL SMALL – allows one data
segment and one code segment
• .DATA –informs data segment begins
• Assembles as .exe file
• .startup – loads data segment register with
segment address
4. Register Indirect Addressing
Transfer a byte , word or double word
between register and memory location
addressed by index or base register
The index and base registers are
BX,BP,SI,DI
Eg MOV AX,[BX] MOV AL,[ECX]
[] – denote indirect addressing
Operation of register indirect
addressing
Examples
• Data segment is used by default with register
indirect addressing
• If BP register address memory stack segment is
used
• Special assembler directive –BYTE PTR, WORD
PTR, DWORD PTR – indicates the size of
memory data address by memory pointer ptr.
• Eg. Mov BYTE PTR[DI],10H
• Used only with instructions that address memory
location through pointer or index register with
immediate data.
An array (TABLE) containing 50 bytes
that are indirectly addressed through register BX
5. Base-Plus-Index Addressing
Transfer a byte , word or double word between
register and memory location addressed by
base register(BP or BX) plus index register
(DI or SI).
Eg. Mov [BX+DI],CL
The base register often holds the beggining
location of the memory array while the index
register holds the relative position of the
element in the array
Locating data with base-plus-index
addressing
Examples
Locating Array data using base plus index
addressing
Example program
6. Register Relative Addressing
Moves a byte , word or double word between
register and memory location addressed by an
index or base register plus a displacement
• BX, DI, or SI addresses the DS segment and
• BP addresses the SS segment
• Displacement can be added or subtracted
• Displacement can be an offset address.
• MOV AX, [BX+1000H]
Operation
Examples
Addressing array data with register
relative
Register relative addressing used to
address an element of ARRAY.The
displacement addresses the start of
ARRAY, and DI accesses an element.
Program addressing array data
using program relative addressing
7. Base Relative-Plus-Index
Addressing
Transfer a byte , word or double word
between register and memory location
addressed by a base register(BP or BX)
and an index register (DI or SI) plus a
displacement.
Eg. MOV AX, [BX+SI+100H]
Operation
Examples
Addressing Arrays with base relative plus
indexed
8. Scaled-Index Addressing
• Uses two 32 bit registers to access
memory the second register is multiplied
by a scale factor
• The scaling factor can be 1X,2X,4X or 8X.
• Eg. MOV AX,[EDI+2*ECX]
Data structures
• Used to specify how information is stored in the memory array.
• STRUC assembly directive and ENDS statement is used to define
a structure.
• Eg defining a structure

INFO STRUC
NAMES DB 32 DUP (?)
STREET DB 32 DUP (?)
CITY DB 16 DUP (?)
INFO ENDS
NAME1 INFO <‘bob smith’ , ‘Cheruthuruthy’, thrissur’>
The literals are surrounded with apostrophes and the entire field is
surrounded with <> symbol.
Use a structure name and field name to select a field from the
structure.
Eg. Name1.names
Program Memory-Addressing
Modes
Used with JMP and CALL instructions
Three distinct forms are
• Direct Program Memory Addressing
• Relative Program Memory Addressing
• Indirect Program Memory Addressing
Direct Program Memory Addressing
• The instruction for direct program memory addressing store
the address with the opcode
• Used by high level languages, BASIC – GOTO and GOSUB
• Eg . The address is stored following the opcode in the
memory

• Inter segment jump means jump to any memory location


with in the memory system.
• Direct jump is often called far jump
• CALL instruction uses direct program addressing
Relative Program Memory Addressing

• Relative means relative to instruction pointer


• Eg.

• A one byte (+127 and -128) displacement is used in short jump and 2
byte (+/- 32k) displacement is used for near jumps and calls
• These jumps are considered to be intra segment jumps
• Means any where with in the current code segment.
• Allows forward memory reference or reverse memory reference
• 32 bit (+/- 2G)displacement is also allowed.
Indirect Program Memory Addressing
Use any 16 bit register, any relative register
If a 16 bit register is used then the jump is near
Eg. JMP BX
If a relative register holds the address it is called indirect-indirect or
double indirect jump
Eg . Mov BX,4
JMP TABLE[BX]
Stack Memory-Addressing
Modes
• Stack holds data temporarily and stores return addresses for
procedures
– The stack memory is LIFO memory
– Use PUSH instruction to place data onto stack
– Use POP instruction to remove data from stack
– Call instruction uses stack to hold return address
– RET instruction remove the return address from the stack
• The stack memory is maintained by two registers: SP or ESP, and
SS
• Always operates on word of data (double word with 386 and above)
• When pushed –high order 8 bits placed in sp-1and low order 8 bits
placed in sp-2 location, sp is then decremented by 2.
• Stack memory address is calculated by adding sp and (ss*10)
• When poped the low order bits are removed form sp and high order
from sp+1 then sp is incremented by 2
Example Push and pop instructions
Example Stack program

You might also like