Professional Documents
Culture Documents
Lecture2 CPU AddrModes
Lecture2 CPU AddrModes
Lecture2 CPU AddrModes
Topics
Intel Microprocessors
8086 CPU Architecture
Addressing Modes of 8086
2
List of Some Intel Microprocessors
Data Address
Maximum
Bus Bus CPU
Microprocessor RAM
Width Width Frequency
(Bytes)
(Bits) (Bits)
8085 8 16 64 KB 3 MHz
8086 16 20 1 MB 5 MHz
80386 16 24 16 MB 16 MHz
80486 32 32 4 GB 25 MHz
Registers in
All Intel Microprocessors
CPU
CPU
Data Bus Register Names
Category Name
Width
4
Intel x86-64
Register Widths 8086 CPU
Intel x86-64
Register Widths 8086 CPU
6
Topics
Intel Microprocessors
8086 CPU Architecture
Addressing Modes of 8086
8
8086 CPU Architecture ADDRESS BUS
20-BIT
AH AL AX
General Address
Purpose BH BL BX
Generation
Registers CH CL CX DATA BUS
DH DL DX 16-BIT
Segment Address
SP Offset Address
Index & CS
Pointer BP Segment DS
Registers SI Registers
SS
DI BUS
ES CONTROL
ALU DATA BUS 16-BIT IP LOGIC
TEMPORARY REGISTERS
Instruction
Decoder
1 2 3 4 5 6
and Queue Bus
ALU EU CONTROL 8-bit
INSTRUCTION QUEUE
6 BYTES
FLAGS REGISTER
10
BIU: Instruction Queue
●
To speed up the execution, 6-bytes of instruction are fetched in
advance, and kept in a 6-byte Instruction Queue called pipe-lining.
●
The queue is used to prefetch and store at the maximum of 6 bytes of
instruction code from the memory.
●
Overlapping the instruction-fetch with the instruction-execution
increases the processing speed.
11
12
Execution Unit (EU)
●
EU is responsible for decoding and executing instructions.
●
It consists of the arithmetic logic unit (ALU), status and control flags,
general purpose registers, and temporary-operand registers.
●
Arithmetic Logic Unit (ALU) can add, subtract, AND, OR, XOR,
increment, decrement, complement or shift binary numbers (8-bit or 16-bit).
●
EU accesses instructions from the output end of the instruction queue
and data from the general purpose registers or memory.
●
It reads one instruction byte after the other from the output of the queue.
●
Decodes the instruction.
●
Generates data addresses if necessary.
●
Passes the addresses to the BIU.
●
Requests the BIU to perform the read or write operations to memory or I/O.
●
Performs the operation specified by the instruction.
13
14
8086 CPU Registers
16 bits
8 bits 8 bits
Accumulator AX AH AL
Base register BX BH BL
General purpose registers
Counter CX CH CL
Data DX DH DL
Stack Pointer SP
Pointers
Base Pointer BP
Instruction Pointer IP
Source Index SI
Index registers Address
Destination Index DI registers
Code Segment CS
Data Segment DS
Segment registers
Stack Segment SS
Extra Segment ES
FLAGS Status register
15
Used as a counter in
Mosltly used as counter for loopings.
string operations, and
CX Counter register Used to hold the count value in SHIFT,
in LOOP instruction.
ROTATE instructions.
17
18
Segment Registers
●
Each segment register is 16-bit, containing address of 64 KB related segment.
●
The segment registers point to the starting location address of a particular segment.
Segment
Segment
Register Description
Register Name
Symbol
Points to base of segment containing machine language code.
SS Stack Segment Data related with stack operations are stored in the stack segment.
All data referenced by the stack pointer (SP) and base pointer (BP)
registers is located in the stack segment.
19
Segment
Registers
ES
SS
CS
DS
00000H
20
Pointer Registers
●
Pointer registers and index registers are 16-bit registers.
●
They are used to store offset addresses of memory locations relative to segment registers.
●
They act as memory pointers.
●
CPU (Address Adder Unit) adds these registers to the shifted segment registers,
in order to obtain the physical memory addresses.
Register Register
Description
Symbol Name
Points to top of stack.
SP Stack Pointer
Used to hold the offset address of top of stack in memory.
The actual stack address is computed by adding content of SP and SS.
Points to base of some data in stack.
Index Registers
Register Register
Description
Symbol Name
Points to a source in array operations.
22
Default and Alternative
Segment Registers
Type of memory
Default segment Alternative segment Offset value
reference
Instruction fetch CS None IP
Stack operation SS None SP, BP
Immediate data DS CS, ES, SS Effective address
String source DS CS, ES, SS SI
String destination ES None DI
Pointer (address in BX) DS CS, ES, SS Effective address
23
Logical Address
Example:
Notation Examples
Suppose content of CS register is = 3482h,
and content of IP register is = 17C6h.
CS : IP
The Logical Address notation can be written as:
SS : SP CS : IP
SS : BP 3482h : 17C6h
ES : DI
24
Physical Memory Address Generation
●
Step1: The Address Adder unit in CPU multiplies the segment address with 16.
In other words, it appends 4 zero bits to the right of segment register,
so that 20 bits width is obtained.
●
Step2: Address Adder unit adds the offset value to the appended value of segment address,
the result is physical memory address (20-bits).
ADDRESS
ADDER
35FE6h
Physical Address = CS * 16 + IP
26
Example2: Generation of 20-bit Physical Address
from SS and SP registers
●
Stack Pointer (SP) register contains the 16-bit offset value from the start of stack
segment to the top of stack.
●
For a stack operation, physical address is produced by adding the content of stack
pointer register to the appended segment base address in SS register.
●
Suppose content of SP = 9F20H , and SS = 4000H.
The physical address (20 bit) is calculated as follows.
(End of SS)
The value after appending zero to SS is 40000H
(Content of SS is not changed by this operation.)
49F20h
(Top of Stack)
Physical Address = SS * 16 + SP
SP= 9F20h
(Offset)
Step1) Append zero to SS = 40000h
Step2) Add the offset (SP) = 9F20h
+ 40000h
Physical Adress = 49F20h (Start of SS)
27
x : Not used
28
Status Flags Register
●
The flag register is a 16-bit register, containing nine status flags (each flag is 1-bit).
●
Flag bits are changed (set to 1) by the results of many Assembly instructions
such as arithmetic, logical, shift/rotate operations.
Flag Bit
Flag Bit Name Description
Symbol
It is set (assigned "1") automatically by ALU, if the result of arithmetic
operation is too large positive number, or is too small negative
OF Overflow Flag
number to fit into destination operand.
OF=1 means there is an overflow.
If set then string manipulation instructions will auto-decrement index
DF Direction Flag registers. If cleared (assigned "0") then the index registers will be
auto-incremented.
IF Interrupt-enable Flag Setting this bit enables maskable interrupts.
TF Single-step Trap Flag If set then single-step interrupt will occur after the next instruction.
Set if the most significant bit of the result is set.
SF Sign Flag SF=0 means the result is positive.
SF=1 means the result is negative.
Set if the result is zero.
ZF Zero Flag
ZF=1 means the result is zero, ZF=0 means the result is not zero.
Set if there was a carry from or borrow to bits 0-3 in the AL register
AF Auxiliary carry Flag
during BCD operation.
Set if parity (the number of "1" bits) in the low-order byte of the result
PF Parity Flag
is even.
Set if there was a carry from or borrow to the most significant bit
CF Carry Flag
during last result calculation. CF=1 means there is a Carry or Borrow. 29
Topics
Intel Microprocessors
8086 CPU Architecture
Addressing Modes of 8086
30
Descriptions of Addresses
●
ADDRESSING MODE :
An instruction consists of an operation code (opcode) and an operand.
The operand may reside in the accumulator, or in a general purpose register,
or in a memory location.
The method in which an operand is specified (or referred to) in an
instruction is called addressing mode.
●
Base Segment Address :
The 16-bit content of one of the four segment registers (CS, DS, ES, SS)
are base segment addresses.
●
Offset Address (Effective address) :
It is contained in the 16-bit registers IP, BP, SP, BX, SI or DI.
●
Physical Address (Real Address) :
Offset and base segment addresses are combined to form a
20-bit physical address that is used to access the memory.
The 20-bit physical address is put on the address bus
(AD0 – AD15 , and A16-A19) by the CPU.
31
3. Direct Addressing
5. Based Addressing
Memory
6. Indexed Addressing operands
32
Generation of Physical Addresses
for different addressing modes
●
Physical address for the operand is the address from which either
a read or write operation is initiated.
●
Effective address, for its generation, can have as many as three elements:
Base register, Index register and Displacement.
●
Both of these addresses are calculated automatically by CPU as follows.
33
34
2. Immediate Addressing Mode
●
The operand (immediate data) is contained in the instruction itself,
i.e., the operand forms a part of the instruction itself.
●
The operand can be either 8-bit or 16-bit in length.
Examples:
35
●
By default, the segment base register is DS.
P.A. = DS : EA
●
A segment prefix can be used in the instruction.
●
General format:
Example1: MOV DS:[2000h], AX
Moves contents of AL to offset address 2000h
(relative to data segment register DS).
Also moves AH contents to address 20001h.
Memory address is supplied within the instruction.
MEMORY
37
38
Example: Direct Addressing Mode
(Accessing a Word data from memory)
●
The example below accesses a Word data (2-byte data) from memory.
●
First byte of data in memory (at address 5001h) is copied to AL register.
(AL is low byte of AX register).
●
Second byte of data in memory (at address 5002h) is copied to AH register.
(AH is high byte of AX register).
●
Storing the low byte of data in low memory address, and high byte of data in high
memory address is called as Little Endian data storage convention.
●
All Intel CPU’s use the Little Endian convention.
●
The opposite is Big Endian convention. Example: Used by Motorola CPU’s.
MEMORY Logical
MOV AX , DS : [5001h] Addresses
AX
5001h Low address
AH AL
5002h High address
High Byte Low Byte
of Data of Data
39
MOV AX, [NUM] ; Move (copy) data from the variable to the register
Base register, or
Example:
MOV AX, [SI]
Moving 16-bit content of memory location
having its offset value in SI, from the beginning
of the current data segment , to the AX register.
Memory address is supplied in an SI index register.
41
42
(SS is default segment for BP usage)
5. Based Addressing Mode
●
The physical address is generated by adding either an 8-bit or 16-bit
displacement to contents of either base register BX or base pointer register BP,
and the current value in DS or SS respectively.
●
General format:
Example:
disp : Displacement
44
6. Indexed Addressing Mode
●
Indexed mode is very similar to the Based Addressing Mode.
●
The difference is that the SI and DI registers are used, instead of BX and BP.
●
General format:
Example:
45
●
General format:
Example:
MOV AL, [BX] [SI]
MOV AL, [BX + SI] ;Same as above
46
Example: Based Indexed Addressing Mode
47
●
General format:
48
Example: Based Indexed plus Displacement
Addressing Mode
49
50
Summary: Examples of Addressing Modes
Suppose: EBX = 00000300H, ESI = 00000200H, ARRAY = 1000H, and DS = 1000H
51
53
Part3
MOV AL , [SI+mesafe] ;6. Indexed Addressing Mode
MOV [SI+mesafe], AL ;6. Indexed Addressing Mode
;Illegal MOV [SI+mesafe], 07h ;6. Indexed Addressing Mode
54