CH 3 Addressing Mode PDF
CH 3 Addressing Mode PDF
•MOV AX, BX
Destination Source
Cont.
• The Source is to the right
• The Destination is to the left, next to the
opcode MOV.
• An Opcode/Operation code, tells the MP
which op’n to perform.
• This Direction of flow, which is applied to
all instructions, is awkward at first.
• A Comma always separates destination
from source in an instruction.
Cont
• Memory-to-memory transfer are not
allowed by any instruction except for MOVS
instruction.
• MOV AX, BX instruction translates the
word contents of the source register (BX)
into the destination register (AX).
• The source never changes, but the
destination usually changes.
Cont.
• Remember that a MOV instruction
always copies the source data & into
destination. The MOV never actually picks
up the data & moves it.
• The flag register remains unaffected by
most data transfer instruction.
• The source & destination are often called
Operands.
Cont.
• see fig. (3-2), P-76, BREY
• Data-addressing modes are as follows:
1. Register addressing:
• Transfers a copy of byte/word from source
register or memory location to destination
register or memory location.
• Exam: MOV CX, DX instruction copies
word-sized contents of register DX into CX.
Fig 3.2: data addressing modes
Cont.
2. Immediate addressing:
•Transfers source-immediate byte or word
of data into destination register or memory
location.
• Exam: MOV AL, 22H instruction copies
a byte sized 22H into register AL.
3. Direct addressing:
• Moves a byte or word bet’n a memory
location & a register.
• Instruction set does not support a memory
to memory transfer except for the MOVS
instruction.
• Exam: MOV CX, LIST instruction copies
word-sized contents of memory location
LIST into register CX.
4. Register indirect addressing:
• Transfers a byte /word bet’n a register & a
memory location addressed by an index or
base register.
• The index & base registers are BP, BX,
DI, & SI.
• Exam: MOV AX, [BX] instruction copies
word-sized data from data segment offset
address indexed by BX into register AX.
5. Base-plus-index addressing:
• Transfers a byte/word bet’n a register &
memory location addressed by a base register
(BP/BX) plus an index register (DI/SI).
• Exam: MOV [BX + DI], CL instruction
copies byte-sized contents of register CL into
data segment memory location addressed by
BX plus DI.
6. Register relative addressing:
• Moves a byte/word bet’n a register &
memory location addressed by an index/base
register plus a displacement.
• Exam: MOV AX, [BX + 4] instruction
loads AX from data segment addressed
formed by BX + 4.
• MOV AX, ARRAY[BX] instruction loads
AX from data segment memory location in
ARRAY plus contents of BX.
7.Base-relative-plus-index addressing:
• Transfers a byte/word bet’n a register &
memory location addressed by a base & an
index register plus a displacement.
• Exam: MOV AX, ARRAY [BX + DI] or
MOV AX, [BX + DI + 4], these instructions
load AX from a data segment memory
location.
•1st instruction uses an addressed formed by
adding ARRAY, BX & DI & 2nd by adding
BX, DI & 4.
REGISTER ADDRESSING:
• Register addressing is the most common
form of data addressing.
• The MP contains the following 8-bit
registers used with register addressing: AH,
AL, BH, BL, CH, CL, DH, & DL.
•16-bit registers: AX, BX, CX, DX, SP, BP,
SI, & DI.
• It is important for instructions to use
registers that are the same size.
Cont.
• Never Mix an 8-bit register with a 16-bit
register because this is not allowed by MP
& results in an error when assembled.
• MOV AX, AL instruction is not allowed
because these registers are of different
sizes.
• Exception: SHL DX, CL
• None of the MOV instructions affect the
flag bits.
Cont.
• See Table (3-1), P-78, BREY.
- A segment-to-segment register MOV instruction
is about only type of register MOV instruction not
allowed.
• Code segment (CS) register is not normally
changed by a MOV instruction, because the
address of the next instruction is fund in both IP &
CS. If only CS were changed, the address of the
next instruction would be unpredictable.
Therefore, changing CS register with a MOV
instruction is not allowed.
Table 3.1: register add. instructions
Cont.
• See fig (3.3), P-79, BREY.
• MOV BX, CX
• source register contents do not changed, but
the destination register’s contents do changed.
• The instruction moves (copies) a 1234H
from register CX into register BX.
• This erases the old contents (76AFH) of
register BX, but the contents of CX remain
unchanged.
Cont.
• The contents of destination
register/destination memory location change for
all instructions except the CMP & TEST ins.
Register array
AX
BX 76 AF 1234
12 34
CX
• MOV BX, CX
Cont.
• Example:
MOV AX, BX; copy contents of BX into CX
MOV CL, DH; copy contents of DH into CL
MOV CL, CH; copy contents of CH into CL
MOV AX, CS; copy contents of CS into DS
MOV DS, AX
MOV CS, AX; assembles, but will cause prob.
• If only contents of CS reg. Change without
changing IP, next step in prog. Is unknown &
Therefore, causes prog. To go away.
IMMEDIATE ADDRESSING:
• Terms Immediate implies that the data
immediately follow the hexadecimal opcode in
memory.
• Immediate data are constant data, while data
transferred from a register are variable data.
• Immediate addressing operates upon a
byte/word of data.
• MOV immediate instruction transfer a copy of
the immediate data into a register/a memory
location.
Cont.
• MOV AX, 3456H instruction copies 3456H
from the instruction, located in the memory
immediately following hexadecimal opcode
into register AX.
Register array
MOV AX, 3456H AX 62 91
BX
3456H
Cont.
• In symbolic assembly language, the symbol #
precedes immediate data in some assemblers
(Hewlet-Packard),
MOV AX, # 3456H
• Most assemblers do not use # symbol, use
MOV AX, 3456H instruction.
• Most common assemblers:
• Intel ASM, Microsoft MASM (MACRO assembler)
•Borland TASM (Turbo ass.), do not use # sym.
Cont.
• Symbolic assembler portrays immediate data
in many ways.
• Letter H appends hexadecimal data.
• If hexadecimal data begin with a letter,
assembler requires data start with a 0.
• Exam: For F2, 0F2H used in assembly lang.
• Decimal data represented as is & require no
special codes or adjustment, (for 100, use
MOV AL, 100).
Cont.
• ASCII coded character/characters may be
depicted in immediate form if ASCII data are
enclosed in apostrophes (MOV BH, ’A’)
moves ASCII coded A (41H) into register BH.
• Binary data represented if binary number is
followed by letter B or letter Y.
•SEE Table (3-2), P-80, BREY.
Table 3.2:immediate addressing
Cont.
• Exam:
LABEL OPCODE OPERAND COMMENT
DATA1 DB 23H ;define DATA1as byte 23H
DATA2 DW 1000H;....DATA2.. word 1000H
START: MOV AL, BL; copy BL into AL
MOV BH, AL; copy AL into BH
MOV CX, 200; copy 200 decimal into CX
•Each statement in a prog. Consists of 04
parts/fields.
Cont.
1. The leftmost field is label, is used to store a
symbolic name for memory location that it
represents.
• All labels must begin with a letter or special
characters: @, $, -, or ?.
• A label may be any length from 1 to 35 charc.
• The label appears in a prog. To identify the
name of a memory location for storing data &
for other purpose.
Cont.
2. Opcode field:
• Designed to hold instruction/opcode (MOV)
3. Operand field:
• Contains information used by opcode
(AL,BL)
4. Comment field:
• Contains a comment about an instruction/a
gr. Of instruction & always begin with (;).
DIRECT DATA ADDRESSING:
• Most instructions can use direct data-
addressing mode.
•Two basic forms of direct data addressing:
1.Direct addressing, which applies to a MOV
bet’n a memory location & AL, AX
2.Displacement addressing: applies to almost
any instruction in the instruction set.
Cont.
• In either case, address is formed by adding
displacement to the default data segment or
alternate segment address.
1. Direct Addressing:
• Direct addressing with a MOV instruction
transfers data bet’n a memory location,
located within data segment & AL (8-bit),
AX (16-bit) register.
Cont.
• MOV AL, DATA {MOV AL,DS:[1234H]}
• loads AL from data segment memory
location DATA (1234H).
• Memory location DATA is a symbolic
memory location, 1234H actual hexadecimal
location.
• SEE fig. (3-5), P-82, BREY.
Cont.
Register array Memory
AX AH AL 8AH 8AH 8A 11235H
BX 11234H
CX 11233H
11232H
CX 01002
DS 01001
0100
01000 01000
DS * 10
DS = 0100H, BX = 1000H, DI = 0010H
Cont.
MOV DX, [BX + DI] or MOV DX,[BX][DI]
DS = 0100H
BX = 1000H
DI = 0010H
for prog. written for Intel
ASM assembler
Locating array data using Base-plus-Index
Addressing:
•A major use of base-plus-index addressing
mode is to address elements in a memory
array.
•Suppose, the elements in an array, located in
data segment at memory location
ARRAY,must be accessed.
•To accomplish this load BX with the
beginning address of array & DI with
element no. to be accessed. See fig(3-9),p-88
Fig 3.9: base plus index addressing. Element (DI) of
an ARRAY (BX) is addressed
ARRAY + 5
DI
ARRAY + 4
Element ARRAY + 3
BX ARRAY + 2
ARRAY + 1
ARRAY ARRAY
Register Relative Addressing:
• Register relative addressing is similar to
base-plus-index addressing & displacement
addressing.
• In register relative addressing, data in a
segment of memory are addressed by adding
displacement to the contents of a base/index
register (BP, BX, DI & SI).
• see fig. (3-10), P-89, BREY.
Cont. memory
Register Array
AX A0 76 A076 A0 3101H
76
BX 01 00 3100H
0100H
1000H +
1100H
DS * 10H
+
2000H 3100H
MOV AX, [BX + 1000H], BX = 0100H, DS = 0200H
Cont.
• Remember, BX, DI, or SI addresses the
data segment & BP Address the stack
segment.
• See Table (3-7), P-90, BREY.
• The displacement can be a no. added to
register within [].
• MOV AL, [DI + 2]
• Displacement subtracted from register,
MOV AL, [SI - 1].
Table 3.7: register relative addressing
Cont.
• Displacement also can be an offset
address appended to the front of [] such as:
MOV AL, DATA [DI]
• Both forms of displacement also can
appear simultaneously,
MOV AL DATA[DI + 3]
• In all cases, both forms of displacement
add to the base or base & index register
within [].
Cont.
•JMP [10000H]
• This JMP instruction loads CS with 1000H &
IP with 0000H to jump to memory location
10000H for the next address.
Cont.
• An intersegment jump is a jump to any
memory location within the entire memory
system.
• Direct jump is often called a far jump,
because it can jump to any memory location
for next instruction.
• In real mode, a far jump accesses any
location within 1M byte of memory by
changing both CS & IP.
Cont.
• The only other instruction that uses direct
program addressing is intersegment or far
CALL instruction.
• Usually, name of a memory address,
called label, refers to the location that is
called or jumped to instead of the actual
numeric address.
2. Relative prog. Memory Addressing:
• Relative program memory addressing is
not available in all early MP.
• Relative means, “relative to the
instruction pointer (IP)”.
• Exam: If a JMP instruction skips the
next two- byte of memory, the address in
relation to the IP is a 2 that adds to the IP.
This develops the address of the next
program instructions.
Cont.
•JMP instruction is a one-byte instruction,
with a one-byte or two-byte displacement
that adds to the IP.
• one-byte displacement is used in short
jumps, & two-byte is used in with near
jumps & calls.
• Both types are considered to be
intrasegment Jumps.
• An intrasegment jump is a jump anywhere
within the current CS.
Cont.
• Relative JMP & CALL instructions contain
either an 8-bit or 16-bit signed displacement
that allows a forward memory reference or a
reverse memory reference.
• An 8 bit displacement(Short) has a jump
range of +127 & -128 bytes from the next
instruction.
• 16bit displacement(near) has a range of
± 32KB. See fig (3-15), P-97, BREY.
Cont.
10000 EB -JMP [2]
10001 02
10002
10003
10004
3.Indirect program Memory Addressing:
• MP allows several forms of program indirect
memory addressing for JMP & CALL
instruction.
• See Table(3-10), P-98, BREY.
• Indirect jump instruction can use of any 16-
bit register: (AX, BX, CX, DX, SP, BP, DI &
SI).
• any relative register: [BP], [BX], [DI] or [SI]
• any relative register with a displacement.
Cont.
• If a 16-bit register holds the address of a
JMP instruction, the jump is near.
• Exam: If BX register contains a 1000H & a
JMP BX instruction executes, MP jumps to
offset address 1000H in the current Code
segment.
• If a relative register holds address, jump
also considered to be an indirect jump.
Cont.
• Exam: JMP [BX] refers to memory
location within data segment at the offset
address contained in BX.
• At this offset address is a 16-bit no. that
used as the offset address in the
intrasegment jump.
• This type of jump is sometimes called an
indirect-indirect or double-indirect Jump.
STACK MEMORY ADDRESSING MODES:
• The stack plays an important role in all MP.
• It holds data temporarily & store return
addresses for procedures.
• Stack memory is a LIFO (Last-in-First-out)
memory, which describes the way that data
are stored & removed from the stack.
• data placed onto stack with a PUSH
instruction & removed with a POP instruction.
Cont.
• CALL instruction also uses the stack to
hold the return address for procedures & a
•RET (return) instruction to remove the
return address from the stack.
• The stack memory is maintained by the
two register:
1. Stack Pointer (SP)
2. Stack Segment (SS)
Cont.
• Whenever a word of data is pushed onto
the stack, the high-order 8-bits are placed in
the location addressed by SP-1.
• Low-order 8bits are placed in the location
addressed by SP-2.
• SP is then decrement by 2 so that next
word of data is stored in the next available
stack memory location.
Cont.
• SP register always points to an area of
memory located within stack segment.
• SP register adds to SS * 10H to form
memory address in real mode.
Cont.
Register Array Memory
AX 42FFF
34 12
BX 12 1234
CX 34 42FFE
DX
SP 3000 +
SS * 10H
PUSH BX
Example: PUSH BX
PUSH [BX] given, DS = 2000H
=2FFE + SS*10H [BX] = 0200H
=2FFE + 40000H [SP] = 3000H
=42FFE [SS] = 4000H
• 3000H - 2 = 2FFE
Cont.
• Whenever data Popped from the
stack, low-order 8-bits are removed
from the location addressed by SP.
• High-order 8-bits are removed from
the location addressed by SP + 1.
• SP register is then incremented by 2.
• PUSH & POP always store or retrieve
words of data-never bytes in 8086.
Cont.
Register Array Memory
AX
12
BX 1234
12 34 34
CX
DX
+
SP
SS * 10H
POP CX
Solve the following Questions:
Q1. List the 8-bit registers that are used for
register addressing.
Q2.List the 16-bit registers that are used foe
register addressing.
Q3. List the 16-bit segment registers used
with register addressing.
Q4. What is wrong with the MOV BL, CX
instruction?
Cont.
Q5. Select an instruction for each of the
following tasks:
a) Copy BL into CL
b) Copy SI into BX
c) Copy DS into AX
d) Copy AL into AH
Q6. What special symbol is sometimes used
to denote immediate data?
Cont.
Q7. Select an instruction for each of the
following tasks:
a) move a 12H into AL
b) move a 123AH into AX
c) move a 0CDH into CL
d) move a 1000H into SI
Q8. The MOV instruction is placed in what
field of a statement?
Q9. What do the symbols [] indicate?
Cont.
Q10. What is displacement? How does it
determine the memory address in a
MOV [2000H], AL instruction?
Q11. What is wrong with a MOV [BX],[DI]
instruction?
Q12. Explain the diff. Bet’n the MOV BX,
DATA instruction & the MOV BX,
OFFSET DATA instruction.
Cont.
Q13. What, if anything, is wrong with a
MOV AL, [BX] [SI] instruction?
Q14. Which base register addresses data in
the stack segment?
Q15. What are the 03 program-addressing
modes?
Q16. How many bytes of memory store a far
direct jump instructions? What is stored in
each of the bytes?
Cont.
Q17. What is the diff. Bet’n an intersegment
& intrasegment jump?
Q18. If a near jump uses a signed 16-bit
displacement, how can it jump to any
memory location within the current code
segment?
Q19. What is a far jump?
Q20. Form a JMP instruction that jumps to
address pointed to by the BX register.
Cont.
Q21. How many bytes are stored on the stack
by PUSH instruction?
Q22. What registers are placed on the stack
by the PUSHA instruction? In what order?
Q23. Explain how the PUSH [DI] instruction
functions.