The 80x86 Microprocessors The 80x86 Microprocessors
The 80x86 Microprocessors The 80x86 Microprocessors
The 80x86 Microprocessors The 80x86 Microprocessors
Markets
Processor
Architecture
Technology Applications
1
Evolution of Intel’s Processors
4004, 1971
2300 Transistors
108 kHz
http://www.intel.com/research/silicon/mooreslaw.htm
The 80x86 Microprocessors 1.3 Assembly Language
1,000
Itanium® proc
(MT)
10
Pentium® Pro
100 Pentium® Pro
1 Pentium proc
486Pentium
486 Pentium® proc
486
386 10 8085
0.1 286 Frequency 286 386
8085 8086
8086
(MHz) 1 8080
0.01 8080
8008 8008
4004
0.001 0.1 4004
’70 ’80 ’90 ’00 ’10
’70 ’80 ’90 ’00 ’10
2
Evolution of Intel’s Processors
Product 4004 8008 8080 8085 8086 8088 80286 80386 80486 Pentium P. Pro
Year 1971 1972 1974 1976 1978 1979 1982 1985 1989 1992 1995
Int. 4 8 8 8 16 16 16 32 32 32 32
Ext. 4 8 8 8 16 8 16 32 32 64 64
Add bus 4 8 16 16 20 20 24 32 32 32 36
3
Evolution from 8086 to 8088
The 8086 is a microprocessor with a 16-bit data bus internally and
externally
All registers are 16 bits wide and there is a 16-bit data bus to transfer
data in and out of the CPU.
At that time all peripherals were designed around an 8-bit microprocessor
instead of 16-bit external data bus .
A printed circuit board with a 16-bit data bus was much more expensive.
Therefore, Intel came out with the 8088 version.
8088 is identical to the 8086 as far as programming is concerned, but
externally it has an 8-bit data bus instead of a 16-bit bus.
8088 has the same memory capacity, 1 megabyte.
In 1981, Intel's fortunes changed forever when IBM picked up the 8088
as their microprocessor of choice in designing the IBM PC.
4
32--bit Microprocessor
32
In 1985 Intel introduced the 80386 (sometimes called 80386DX), internally
and externally a 32
32--bit microprocessor with a 32-bit address bus.
It is capable of handling physical memory of up to 4 gigabytes (232).
Virtual memory was increased to 64 terabytes (246).
Intel introduced numeric data processing chips, called math coprocessors,
such as the 8087, 80287, and 80387.
Later Intel introduced the 386SX, which is internally identical to the 80386
but has a 16-bit external data bus and a 24-bit address bus which gives a
capacity of 16 megabytes (224) of memory.
This makes the 386SX system much cheaper.
With the introduction of the 486 in 1989, Intel put a greatly enhanced
version of the 386 and the math coprocessor on a single chip plus
additional features such as cache memory.
Cache memory is static RAM with a very fast access time.
Pentium
In 1992 Intel introduced the Pentium.
The Pentium had speeds of 60 and 66 MHz, but new design features
made its processing speed twice that of the 66-MHz 80486.
Although the Pentium has a 64--bit data bus, its registers are 32-bit and
64
it has a 32
32--bit address bus capable of addressing 4 gigabyes of
memory.
In 1995 Intel introduced the Pentium Pro, the sixth generation of the x86
family.
Pentium Pro is an enhanced version of the Pentium.
5
Internal Block Diagram of the 8088
8088//86 CPU
EXECUTION UNIT (EU) BUS INTERFACE UNIT (BIU)
address
generation and
bus control
Pipelining
There are two ways to make the CPU process information faster:
1. Increase the working frequency or
2. Change the internal architecture of the CPU
The first option is technology dependent, meaning that the designer must
use whatever technology is available at the time, with consideration for
cost.
The technology determines the working frequency, power consumption,
and the number of transistors packed into a single-chip microprocessor.
The second option for improving the processing power of the CPU has to
do with the internal working of the CPU.
In the 8085 microprocessor, the CPU could either fetch or execute at a
given time.
6
Pipelining (Cont.)
The idea of pipelining in its simplest form is to allow the CPU to fetch and
execute at the same time.
Fetch Execute
Fetch Execute
2-stage pipeline
Fetch Execute
7
8088//86 Registers
8088
Registers: used to store information temporarily.
Information: data (8/16-bit) to be processed or the address of data.
8-bit/
bit/16
16--bit Registers
8-bit registers
16-bit registers
8
Introduction to Assembly Programming
9
MOV Instruction
The MOV instruction copies data from one location to another.
MOV destination, source ;copy source operand to destination
Destination Source
The MOV instruction does not affect the source operand.
MOV AX, 35A0H
AH AL High byte Low byte
35 A0
AX 00110101 10100000
00110101 10100000
10
Immediate MOV
Data can be moved directly into nonsegment registers only, using the
MOV instruction
11
ADD instruction
ADD destination, source ;ADD the source operand to the destination
16--bit Addition
16
To add two numbers such as 34EH and 6A5H:
12
Introduction to Program Segments
A typical Assembly language program consists of at least three segments:
8085//8086 Segments
8085
A segment is an area of memory
includes up to 64K bytes and
begins on an address evenly divisible by 16 (address ends in 0H).
8085 microprocessor had only 16 pins for the address lines (216 = 64K).
8085 microprocessor could address a maximum of 64K bytes of physical
memory for code, data, and stack.
For compatibility
compatibility, 64K bytes segment was carried into the design of the
8088/86.
Three segments can be used: code, data, and stack segments.
8088/86 can only handle a maximum of 64K bytes of code and 64K bytes
of data and 64K bytes of stack at any given time, although it has a range
of 1 megabyte of memory (20 address pins 220 1 megabyte).
13
Logical address and physical address
In Intel literature, there are three types of addresses mentioned frequently:
Physical address
20-bit address that is actually put on the address pins of the 8086
microprocessor and decoded by the memory interfacing circuitry.
This address can have a range of 00000H to FFFFFH.
Offset address
a location within a 64K-byte segment range.
An offset address can range from 0000H to FFFFH.
Logical address
The logical address consists of a segment value and an offset
address
Code segment
To execute a program, the 8086 fetches the instructions (opcodes and operands)
from the code segment.
The logical address of an instruction, CS:IP
The physical address for the location of the instruction is
CS10H + IP Shifting the CS left one hex digit and then adding it to the IP
CS or IP is 16-bit register, the physical address (CS10H + IP) is 20-bit.
Example: assume CS = 2500H and IP = 95F3H.
The offset address: 95F3H (the content of IP)
The logical address: 2500:95F3H (CS:IP)
The physical address: 250010 + 95F3 = 2E5F3H
The logical address range: 2500:0000 to 2500:FFFF
The lowest memory location of the code segment: 25000H (25000+0000)
The highest memory location of the code segment: 34FFFH (25000+FFFF)
8086 will read the instruction from memory locations starting at 2E5F3H
14
Example
If CS = 24F6H and IP = 634AH
Calculate: (c) The physical address (d) The lower range of the code segment
(e) The upper range of the code segment
Solution:
(a) The logical address 24F6:634A
(d) The lower range of the code segment 24F60 (24F610 + 0000)
(e) The upper range of the code segment 34F5F (24F610 + FFFF)
80x
80 x86 ADDRESSING MODES
The CPU can access operands (data) in various ways, called addressing
modes.
15
Register addressing mode
The operands are inside the microprocessor.
The register addressing mode involves the use of registers to hold the
data to be manipulated.
Memory is not accessed when this addressing mode is executed;
It is relatively fast
Examples:
MOV BX,DX ; copy the contents of DX into BX
MOV ES,AX ; copy the contents of AX into ES
ADD AL,BH ; add the contents of BH to contents of AL
16
Direct addressing mode
In the direct addressing mode the data is in some memory location(s) and
the address of the data in memory comes immediately after the
instruction.
Note that in immediate addressing, the operand itself is provided with the
instruction, whereas in direct addressing mode, the address of the
operand is provided with the instruction.
This address is the offset address and one can calculate the physical
address by shifting left the DS register and adding it to the offset as
follows:
MOV DL,[2400] ;move contents of DS:2400H into DL
Notice the bracket [ ] around the address.
In the absence of this bracket it will give an error since it is interpreted to
move the value 2400 (16-bit data) into register DL, an 8-bit register.
MOV DL,2400 ; move 2400 into DL illegal
Example
Find the physical address of the memory location and its contents after
the execution of the following instructions
assuming that DS = 1512H.
MOV AL,99H ; AL is initialized to 99H
MOV [3518],AL
Solution:
The contents of AL are moved to logical address DS:3518 which is
1512:3518.
The physical address: 18638H (151210H + 3518H = 18638H).
That means after the execution of the second instruction, the memory
location with address 18638H will contain the value 99H.
17
Register indirect addressing mode
In the register indirect addressing mode, the address of the memory location
where the operand resides is held by a register.
The registers used for this purpose are SI, DI, and BX.
If these three registers are used as pointers, they must be combined with DS
in order to generate the 20-bit physical address.
Example:
MOV AL,[BX] ; AL contents of the memory location pointed to by DS:BX
Notice that BX is in brackets.
In the absence of brackets: MOV AL,BX illegal
Physical address: DS10H+ BX
The same rules apply when using register SI or DI.
MOV CL,[SI] ; move contents of DS:SI into CL (move a byte)
MOV [DI],AH ; move contents of AH into DS:DI (move a byte)
Example
Assume that DS = 1120, SI = 2498, and AX = 17FE. Show the contents of
memory locations after the execution of
MOV [SI],AX
Solution:
The contents of AX are moved into memory locations with logical
address DS:SI and DS:SI + 1
The physical address: DS10H + SI = 13698.
According to the little endian convention
low address 13698H contains FE, the low byte, and
high address 13699H will contain 17, the high byte.
18
Based relative addressing mode
In the based relative addressing mode, base registers BX and BP, as well
as a displacement value, are used to calculate what is called the physical
address.
Physical address = segment register
register10
10H
H + offset register + displacement
The default segments are DS for BX and SS for BP.
For example:
MOV CX,[BX]+10 ; move DS:BX+10 and DS:BX+10+1 into CX
MOV CX,[BX+10] ; BX+10 is called the effective address
MOV CX,10[BX] ; BX is called the offset address
Physical address: DS10H + BX + 10
The low address contents will go into CL and the high address contents into
CH. In the case of the BP register,
MOV AL,[BP]+5 ; PA = SS 10H + BP + 5
MOV AL,[BP+5] ; BP+5 is called the effective address
MOV AL,5[BP] ; BP is called the offset address
Example
Assume that DS = 4500, SS = 2000, BX = 2100, SI = 1486, DI = 8500, BP
= 7814, and AX = 2512. Show the exact physical memory location where
AX is stored in each of the following. All values are in hex.
MOV [BX]+20,AX MOV [SI]+10,AX MOV [DI]+4,AX MOV [BP]+12,AX
Solution:
DS:BX+20 location 47120 = (12) and 47121 = (25)
DS:SI+10 location 46496 = (12) and 46497 = (25)
DS:DI+4 location 4D504 = (12) and 4D505 = (25)
SS:BP+12 location 27826 = (12) and 27827 = (25)
19
Based indexed addressing mode
By combining based and indexed addressing modes, a new addressing
mode is derived called the based indexed addressing mode.
In this mode, one base register and one index register are used.
Examples:
MOV CL,[BX][DI]+8 ; PA = DS10H + BX + Dl + 8
MOV CH,[BX][SI]+20 ; PA = DS 10H + BX + SI + 20
MOV AH,[BP+SI+29]
MOV AH,[SI+BP+29] ;the register order does not matter.
Summary of 80
80xx86 Addressing Modes
Addressing Mode Operand Default Segment
Register register none
Immediate data none
Direct [offset] DS
Register indirect [BX] DS
[SI] DS
[DI] DS
Based relative [BX]+disp DS
[BP]+disp SS
Indexed relative [DI]+disp DS
[SI]+disp DS
Based indexed relative [BX][SI]+disp DS
[BX][DI]+disp DS
[BP][SI]+ disp SS
[BP] [DI]+ disp SS
The 80x86 Microprocessors 1.40 Assembly Language
20
Offset Registers for Various Segments
Segment register: Offset register (s):
CS IP
DS SI, DI, BX
ES SI, DI, BX
SS SP, BP
The 80x86 CPU allows the program to override the default segment and
use any segment register.
MOV AL,[BX]
; the physical address of the operand to be moved into AL is DS:BX
MOV AL,ES:[BX]
; the address of the operand being moved to AL is ES:BX instead of
DS:BX.
Segment overrides
Default Segment
Instruction Instruction
Segment Used
21
Translating to Machine Code
Translate the following Assembly language instructions into machine code
MOV AL,57H
MOV DH,86H
MOV DL,72H
MOV CX,DX
MOV BH,AL
MOV BL,9FH
MOV AH,20H
ADD AX,DX
ADD CX,BX
ADD AX,1F35H
22
MOV Immediate Value to 8-bit Registers
10110 Reg 8-bit data
MOV AL,57H
Reg
10110 000 01010111 AL 000
CL 001
1011000001010111 B057
DL 010
MOV DH,86H BL 011
AH 100
10110 110 10000110 CH 101
DH 110
1011011010000110 B686 BH 111
MOV DL,72H
10110 010 01110010
1011001001110010 B272
The 80x86 Microprocessors 1.45 Assembly Language
MOV Immediate to 16
16--bit Registers
MOV AX,1F35H
10111 000 0001111100110101 Reg
AX 000
101110000001111100110101 B81F35 CX 001
DX 010
MOV DX,86H BX 011
SP 100
10111 010 0000000010000110 BP 101
SI 110
101110100000000010000110 BA0086 DI 111
23
MOV from 8-bit Registers to 8-bit Registers
1000100011 Regsource Regdestination
• MOV BH,AL
• 1000100011000111 Reg
• 1000100011000111 88C7 AL 000
CL 001
DL 010
BL 011
AH 100
CH 101
DH 110
BH 111
MOV from 16
16--bit Registers to 16
16--bit Registers
MOV CX,DX
1000100111010001 Reg
AX 000
1000100111010001 89D1 CX 001
DX 010
BX 011
SP 100
BP 101
SI 110
DI 111
24
Machine Code
Logical address Physical address Machine code contents
1132:0100 11420 B0
1132:0101 11421 57
1132:0102 11422 B6
1132:0103 11423 86
1132:0104 11424 B2
1132:0105 11425 72
1132:0106 11426 89
1132:0107 11427 D1
1132:0108 11428 88
1132:0109 11429 C7
1132:010A 1142A B3
1132:010B 1142B 9F
1132:010C 1142C B4
1132:010D 1142D 20
1132:010E 1142E 01
1132:010F 1142F D0
1132:0110 11430 01
1132:0111 11431 D9
1132:0112 11432 05
1132:0113 11433 35
1132:0114 11434 1F
The 80x86 Microprocessors 1.49 Assembly Language
Data Segment
Write a program that adds 5 bytes of data, such as 25H, 12H, 15H, 1FH,
and 2BH, where each byte represents a person's daily overtime pay.
Answer
MOV AL,0 ; initialize AL
ADD AL,25H ; add 25H to AL
ADD AL,12H ; add 12H to AL
ADD AL,15H ; add 15H to AL
ADD AL,1FH ; add 1FH to AL
ADD AL,2BH ; add2BHtoAL
-ve
The data and code are mixed together in the instructions.
Changing in data the code must be searched for every place the
data is included, and the data retyped.
In 80x86 microprocessors, the area of memory set aside for data is called
the data segment.
the data segment uses register DS and an offset value.
25
Data Segment (Cont.)
Assume that the offset for the data segment begins at 200H.
The data is placed in memory locations:
DS:0200 = 25
DS:0201 = 12
DS:0202 = 15
DS:0203 = 1F
DS:0204 = 2B
The program can be rewritten as follows:
MOV AL, 0 ; clear AL
ADD AL,[0200] ; add the contents of DS:200 to AL
ADD AL,[0201] ; add the contents of DS:201 to AL
ADD AL,[0202] ; add the contents of DS:202 to AL
ADD AL,[0203] ; add the contents of DS:203 to AL
ADD AL,[0204] ; add the contents of DS:204 to AL
The brackets [ ] indicate that the operand represents the address of the
data and not the data itself.
26
Logical and Physical address in Data Segment
Solution:
(a) The physical address 83DAE (7FA20 + 438E)
(b) The lower range of the data segment 7FA20 (7FA20 + 0000)
(c) The upper range of the data segment 8FAlF (7FA20 + FFFF)
(d) The logical address 7FA2:438E
Example
Assume that the DS register is 578C. To access a given byte of data at
physical memory location 67F66, does the data segment cover the range
where the data is located? If not, what changes need to be made?
Solution:
27
What is a stack, and why is it needed?
The stack is a section of read/write memory (RAM) used by the CPU to
store information temporarily.
The CPU needs this storage area since there are only a limited number of
registers.
The main disadvantage of the stack is its access time.
The two main registers used to access the stack are the SS (stack
segment) register and the SP (stack pointer) register.
These registers must be loaded before any instructions accessing the
stack are used.
Every register inside the 80x86 (except segment registers and SP) can be
stored in the stack and brought back into the CPU from the stack memory.
The storing of a CPU register in the stack is called PUSH, and loading the
contents of the stack into the CPU register is called POP.
In the 80x86, the stack pointer register (SP) points at the current memory
location used for the top of the stack and as data is pushed onto the stack
it is decremented.
SP is incremented as data is popped off the stack into the CPU.
Example
Assuming that SP = 1236, AX = 24B6, DI = 85C2, and DX = 5F93,
show the contents of the stack as each of the following instructions is
executed:
PUSH AX
PUSH DI
PUSH DX BX = 5F93
POP BX
POP AX AX = 85C2
POP CX CX = 24B6
SS:1230 93
SS:1231 5F
SS:1232 C2 C2 C2
SS:1233 85 85 85
SS:1234 B6 B6 B6 B6 B6
SS:1235 24 24 24 24 24
SS:1236
PUSH AX PUSH DI PUSH DX POP BX POP AX POP CX
The 80x86 Microprocessors 1.56 Assembly Language
28
Example
Assuming that SP = 1236, AX = 24B6, DI = 85C2, and DX = 5F93,
show the contents of the stack as each of the following instructions is
executed:
PUSH AX
PUSH DI
POP BX AX = 5F93
PUSH DX
POP AX BX = 85C2
POP CX CX = 24B6
SS:1230
SS:1231
SS:1232 C2 93
SS:1233 85 5F
SS:1234 B6 B6 B6 B6 B6
SS:1235 24 24 24 24 24
SS:1236
PUSH AX PUSH DI POP BX PUSH DX POP AX POP CX
The 80x86 Microprocessors 1.57 Assembly Language
Yes
Logical address (hex) Physical address (hex)
1000:5020 15020
1500:0020 15020
1502:0000 15020
1400:1020 15020
1302:2000 15020
29
Flag register (status register)
The flag register is a 16-bit register.
Only 9 of the bits are used and the rest are either undefined or reserved by
Intel.
6 of the flags are called conditional flags: CF, PF, AF, ZF, SF, and OF
They indicate some condition that resulted after an instruction was
executed
3 flags are sometimes called control flags: DF, IF, and TF
They are used to control the operation of instructions before they are
executed.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R R R R OF DF IF TF SF ZF U AF U PF U CF
R = reserved U = undefined
CF = carry flag PF = parity flag AF = auxiliary carry flag
ZF = zero flag SF = sign flag OF = overflow flag
DF = direction flag IF = interrupt flag TF = trap flag
a7 a6 a5 a4 a3 a2 a1 a0
OP
b7 b6 b5 b4 b3 b2 b1 b0
C r7 r6 r5 r4 r3 r2 r1 r0
30
Bits of the flag register (Cont.)
SF: Sign Flag
Signed numbers uses the most significant bit as the sign bit. After
arithmetic or logic operations, the status of this sign bit is copied into
the SF, thereby indicating the sign of the result.
TF: Trap Flag
When this flag is set it allows the program to single-step, meaning to
execute one instruction at a time.
Single-stepping is used for debugging purposes.
IF: Interrupt Enable Flag
This bit is set or cleared to enable or disable only the external
maskable interrupt requests.
DF: Direction Flag
This bit is used to control the direction of string operations.
OF: Overflow Flag
This flag is set whenever the result of a signed number operation is
too large, causing the high-order bit to overflow into the sign bit.
In general, the carry flag is used to detect errors in unsigned
arithmetic operations.
The overflow flag is only used to detect errors in signed arithmetic
operations.
The 80x86 Microprocessors 1.61 Assembly Language
31
Example
Show how the flag register is affected by the addition of 38H and 2FH
MOV BH,38H ; BH= 38H
ADD BH,2FH ; add 2F to BH, now BH = 67H
Solution:
38 0011 1000
2F 0010 1111
67 0110 0111
Example
Show how the flag register is affected by
MOV AL,9CH ; AL = 9CH
MOV DH,64H ; DH = 64H
ADD AL,DH ; now AL=0
Solution:
9C 1001 1100
64 0110 0100
00 0000 0000
32
Use of the zero flag for looping
One of the most widely used applications of the flag register is the use of
the zero flag to implement program loops.
The term loop refers to a set of instructions that is repeated a number of
times.
MOV CX,05 ;CX holds the loop count
MOV BX,0200H ;BX holds the offset data address
MOV AL,00 ;initialize AL
ADD_LP: ADD AL,[BX] ;add the next byte to AL
INC BX ;increment the data pointer
DEC CX ;decrement the loop counter
JNZ ADD_LP ;jump to next iteration if counter not zero
33
Operations on Flags
CLC
CLC: Clear Carry Flag CF = 0
STC
STC: Set Carry Flag CF = 1
CMC
CMC: Complement Carry Flag if CF = 0 CF = 1, otherwise CF = 0
CLD
CLD: Clear Direction Flag DF = 0
STD
STD: Set Direction Flag DF = 1
CLI
CLI: Clear Interrupt Flag IF = 0
STI
STI: Set Interrupt Flag IF = 1
34
Jump
Unconditional Jump
xxx: ………
………
………
JMP xxx
Conditional Jump
xxx: ………
………
………
JC xxx JNC xxx
JZ xxx JNZ xxx
JP xxx JNP xxx
JO xxx JNO xxx
JS xxx JNS xxx
Unsigned Numbers
Unsigned numbers: Data in which all the bits are used to represent data
and no bits are set aside for the positive or negative sign.
An 8-bit operand ranges from 00 to FFH (0 to 255 decimal)
A 16-bit operand ranges from 0000 to FFFFH (0 to 65535 decimal)
for and between 0000 and FFFFH (O to 65535 decimal)
Example: A byte of memory contains (A3)16.
What decimal number does this represent if the byte is interpreted as
containing: - an eight-bit unsigned integer.
- an eight-bit signed integer.
Answer:
Unsigned integer (A3)16 =
(10100011)2 = 271 + 260 + 251 + 240 + 230 + 220 + 211 + 201 = 163
Signed integer (A3)16 =
(A3)16 = (10100011)2 = - (01011101)2
- (270 + 261 + 250 + 241 + 231 + 221 + 210 + 201) = -93
35
Addition of unsigned numbers
ADD destination, source ; destination = destination + source
ADC destination, source ; destination = destination + source + CF
The destination operand can be a register or in memory.
The source operand can be a register, in memory, or immediate.
Remember that memory-to-memory operations are never allowed in
80x86 Assembly language.
The instruction could change any of the ZF, SF, AF, CF, or PF bits of the
flag register, depending on the operands involved.
Example: Show how the flag register is affected by
MOV AL,0F5H F5 11110101
+
ADD AL,0BH 0B 00001011
After the addition, the AL register (destination) contains 00 100 100000000
CF = 1 since there is a carry out from D7
SF = 0 the status of D7 of the result
PF = 1 the number of 1s is zero (zero is an even number)
AF = 1 there is a carry from D3 to D41.71
The 80x86 Microprocessors Assembly Language
Example
Show how the flag register is affected by
MOV AL,0F5H
ADD AL,0BH
F5 11110101
+
0B 00001011
100 100000000
36
Addition of individual byte and word data
Write a program to calculate the total sum of 5 bytes of data. Each byte
represents the daily wages of a worker. This person does not make more than
$255 (FFH) a day. The decimal data is as follows: 125, 235, 197, 91, and 48
COUNT EQU 05
DATA DB 125, 235, 197, 91, 48
SUM DW ?
MOV AX,DTSEG
MOV DS, AX
MOV CX,COUNT
MOV SI, OFFSET DATA
MOV AX,00
BACK ADD AL,[SI]
JNC OVER
INC AH
OVER INC SI
DEC CX
JNZ BACK
MOV SUM,AX
MOV AH, 4CH
INT 21H
37