Chapter 2 Addressing Modes 2009 V STD
Chapter 2 Addressing Modes 2009 V STD
1
Outline
Programming Overview
Programming Language Levels
Addressing Modes
Register and Immediate
Memory
I/O
Relative
Implied
2
Programming Overview
Programming Language Levels
There are three programming language levels that can be used to write programs
for a microcomputer
Machine Language
Assembly Language
High Level Language
Machine Language
Sequence of binary codes
Very difficult to understand and error prone
To make it easier, HEX representation is used
E.g. 1011 1000 B8
1001 0100 94
0000 0001 01
This is binary code for the 8086 instruction
MOV AX, 0194H
3
Programming Overview
Programming Language Levels…
Assembly language
Makes programming easier
A special program called assembler is required to translate it to
machine language
Uses two-, three- or four-letter mnemonics to represent each
instruction type
Mnemonics in assembly languages
Initials or shortened form of the operation performed by the instruction
Statements usually written in a standard form that consists of
four fields
LABEL OP CODE OPERAND COMMENT FIELD
FIELD FIELD FIELD
NEXT: ADD AL, 07H ;ADD
CORRECTION
FACTOR 4
Programming Overview
Programming Language Levels…
Assembly language…
Label Field
A symbol or group of symbols used to represent an address
which is not specifically known at the time the statement is
written
Usually followed by a colon
Not required in every statement, inserted where it is needed
Op Code Field
Contain mnemonic for the instruction to be performed
E.g.LABEL
ADD is theOPmnemonic
CODE for the instruction
OPERAND to do addition
COMMENT FIELD
FIELD FIELD FIELD
NEXT: ADD AL, 07H ;ADD CORRECTION
FACTOR 5
Programming Overview
Programming Language Levels…
Assembly language…
Operand Field
Contains the data, the memory address, the port address or the name of the register on
which the instruction is performed
Operand is another name for data items to be acted up on by an instruction
E.g. The figure below contain two operands 07H and AL
Comment Field
Starts with a semicolon, not part of the machine language program
Reminds the function that an instruction or group of instructions performs in the
program
To convert assembly to machine
Manual: E.g. MOV AX, 0194 B8 94 01 BINARY
Use assembler
LABEL OP CODE OPERAND COMMENT FIELD
FIELD FIELD FIELD
NEXT: ADD AL, 07H ;ADD CORRECTION
FACTOR 6
Addressing Modes
The different ways in which a processor can access
data that it operates on
Indicated in the instruction in assembly languages
E.g. Move instruction format
MOV destination, source
Copies a word or byte from the specified source location to the
specified destination location
Source – could be a number, register or memory location
Destination – can be register or memory (1 of 24 ways)
Both source and destination can’t be memory locations in an
instruction
7
Addressing Modes…
The 8086 has 12 basic addressing modes that can be
classified into five groups
Register and Immediate
Memory
I/O
Relative
Implied
8
Addressing Modes…
Immediate
8 or 16-bit data can be specified as part of the instruction
E.g. MOV CX, 437BH
Puts immediate hexadecimal number 437B in the 16-bit CX register
E.g. MOV CL, 48H
Puts immediate hexadecimal number 48 in the 8-bit CL register
Immediate:
Because the number to be loaded into CX/CL will be put in
memory locations immediately following the code for the move
instruction
Data part of the instruction
Located in the memory addressed by CS and IP registers
9
Addressing Modes…
Register
A register is the source, destination or both of an
operand for the instruction
E.g. MOV CX, AX
Copies contents of the AX register into 16-bit CX register
Any 16-bit register can be moved to any 16-bit register
Any 8-bit register can be moved to any 8-bit register
BUT register sizes must be the same
E.g. MOV BX, CH is ILLEGAL!
10
Addressing Modes…
Memory
Used to specify location of an operand in memory
8086 provides 17 different ways to access memory
To access data, Effective Address (EA) is added to
segment base address
The EA represents the displacement (offset) of the
operand from the segment base
EU calculates EA for an operand from the information
specified in the instruction
Depending on the way the EA is provided to EU
There are various memory addressing modes
11
Memory Addressing Modes…
Direct
The simplest memory addressing mode
EA is 16-bit number written directly in instruction
E.g. 1
MOV BL, [437AH]
base into BL
Direct
Displacement of operand from segment base is specified
directly in the instruction
segment
Contents of BL copied to memory location at displacement of 437AH
13
Memory Addressing Modes…
Register Indirect
EA is specified in either a pointer or index register
Pointers
Base Register (BX) & Base Pointer Register (BP)
Index
Source Index (SI) & Destination Index (DI)
The 20-bit physical address is computed using DS and EA
E.g. MOV [DI], BX
Copies content of BX into memory at offset DI from current DS
E.g. If [DS] = 5004H, [DI] = 0020H and [BX] = 2456H,
Then after MOV [DI], BX content of BX (2456H) is moved to
memory locations 50060H and 50061H
14
Memory Addressing Modes…
Based
EA is obtained by adding a displacement to contents
of BX or BP
The displacement can be signed 8-bit or unsigned 16-bit
DS and SS become segment registers for BX and BP
respectively
E.g. MOV AL, START[BX] or, MOV AL, [BX+START]
EA is obtained by adding value of START and [BX]
Based addressing mode provides convenient way to
address structure which may be stored at different
places in memory
15
Memory Addressing Modes…
Indexed
EA is calculated by adding the unsigned 16-bit or sign-
extended 8 bit displacement and contents of SI or DI
E.g. MOV BH, START[SI]
Moves contents of 20-bit address computed from
displacement START, SI and DS into BH
The displacement START is provided by the programmer
using the assembler pseudo instruction
Indexed addressing can be used to access a single table,
where displacement is starting address of table
SI/DI used as an index to access a particular element in
the table
16
Memory Addressing Modes…
Based and Indexed
EA is computed by adding base register (BX or BP), and
index register (SI or DI), and displacement
E.g. MOV ALPHA[SI][BX], CL
If [BX] = 0200H, ALPHA = 08H, [SI] = 1000H, & [DS] = 3000H,
then 8-bit content of CL is moved to 20-bit physical address
31208H
Provides a convenient way for a subroutine to address
an array allocated on a stack
BP loaded with offset in stack segment, SS
Displacement, a value which is the difference b/n top of
the stack and the beginning of the array
17
Memory Addressing Modes…
String
Uses index registers
String instructions automatically assume
SI to point to first byte/word of source string/operand
DI to point to first byte/word of destination operand
Contents of SI & DI automatically incremented
By clearing the direction flag to 0 by CLD instruction
Contents of SI & DI automatically decremented
By setting the direction flag to 1 by STD instruction
Segment register for source is DS (can be overridden)
Segment register for destination is ES (cannot be
overridden)
18
Addressing Modes…
I/O
Memory mapped I/O uses memory addressing modes
Standard I/O uses port addressing modes
19
Addressing Modes…
Relative & Implied
Relative
Operand is specified as signed 8-bit displacement
relative to PC
E.g. JNC START
Implied
Instructions using this mode have no operands
E.g. CLC - clears carry flag to zero
20
End of Chapter 2
21