8086 Principles and Programing
8086 Principles and Programing
Bore Gowda S B
ECE Department
Manipal Institute of Technology
Manipal-576104
Introduction
What is computer ?
Programmable electronic device that can store, retrieve, and
process data.
or
Evolution of Computers
First generation (1939-1954) - vacuum tube
Second generation (1954-1959) transistor
Third generation (1959-1971) IC
Fourth generation (1971-present) microprocessor
Input
Devices
Central Processing
Unit (CPU)
Memory Devices
Output
Devices
Computers organization
What is Microprocessor?
It is a multipurpose, programmable device that accepts digital
data as input, processes it according to instructions stored in its
memory, and provides results as output.
The P is the brain of the microcomputer
It is a single chip which is capable of
processing data
controlling all of the components which make up the
microcomputer system
P used to sequence executions of instructions that is in
memory
P Fetch , Decode , and Execute the instruction
The internal architecture of the microprocessor is complex.
Year
Transistor
count
Clock
(MHz)
Memory
4004
1971
2250
0.108
4-bit
4-bit
--
---
8080
1974
6000
2-3
8-bit
8-bit
16-bit
64KB
8085
1976
6500
3-8
8-bit
8-bit
8086
1978
29000
5-10
16-bit
16-bit
16-bit 64KB
20-bit 1MB
8088
1979
29000
5-8
16-bit
8-bit
80286
1982
134000
8-12
32-bit
16-bit
80386
1985
275000
16-33
32-bit
32-bit
80486
1989
1.2million
25-100
32-bit
32-bit
Pentium
1993
3.1million
60-233
32-bit
64-bit
Pentium Pro
1995
5.5million
64-bit
Pentium II
1997
7.5million
150-200 32-bit
233-400 32-bit
Pentium III
1999
28.1million
550
32-bit
20-bit 1MB
24-bit 16MB
32-bit 4GB
32-bit 4GB
32-bit 4GB
36-bit 4GB
Introduction to 8086
Released by Intel in 1978
Produced from 1978 to 1990s
A 16-bit microprocessor chip.
Max. CPU clock rate :
5 MHz to 10 MHz
Package: 40 pin DIP
The 8086 gave rise to the x86
architecture of Intel's future
processors.
Common
manufacturer(s):
Intel, AMD, NEC, Fujitsu,
Harris (Intersil), OKI, Siemens
AG,
Texas
Instruments,
Mitsubishi.
8086 Architecture
The 8086 has two parts, the Bus Interface Unit (BIU) and the
Execution Unit (EU).
The BIU fetches instructions, reads and writes data, and
computes the 20-bit address.
The EU decodes and executes the instructions using the 16bit ALU.
BIU
8086 Architecture
EU
Execution Unit
(EU)
AH
AL
BH
BL
CH
CL
DH
DL
General purpose
register
SP
Segment
register
BP
SI
DI
CS
Data bus
(16 bits)
DS
SS
ALU
Flag register
ES
IP
Instruction Queue
EU
control
Bus
control
External bus
1 2 3 4 5 6
Bus Interface Unit (BIU)
BIU Operation
The BIU fetches instructions using the CS and IP, written
CS:IP, to construct the 20-bit address.
Data is fetched using a segment register (usually the DS)
An effective address (EA) computed by the EU
depending on the addressing mode.
Components in BIU
Segment register
The instruction pointer
Address generation adder
Bus control logic
Instruction queue
EU Operation
1. Fetch an instruction from instruction
queue
2.
AH
BH
CH
DH
AL
BL
CL
DL
SP
BP
SI
DI
ALU
Flag register
General purpose
register
EU
control
instruction
1011000101001010
Components in EU
Arithmetic logic unit(ALU)
Status and control flags
General-purpose registers
Temporary-operand registers
BIU registers
(20 bit adder)
AX
BX
CX
DX
AH
BH
CH
DH
16 bit arithmetic
Stack Segment
Data Segment
Instruction Pointer
AL
BL
CL
DL
SP
BP
EU registers
Extra Segment
Code Segment
SI
DI
FLAGS
Accumulator
Base Register
Count Register
Data Register
Stack Pointer
Base Pointer
Source Index Register
Destination Index Register
Flag Register
Flag register contains information reflecting the current
status of a microprocessor. It also contains information
which controls the operation of the microprocessor.
Called as Program Status Word (PSW)
15
14
13
12
11
10
OF DF
IF
TF SF ZF
Control Flags
IF:
DF:
TF:
AF
PF
CF
Status Flags
CF:
PF:
AF:
ZF:
SF:
OF:
Carry flag
Parity flag
Auxiliary carry flag
Zero flag
Sign flag
Overflow flag
15
CS
Code Segment
DS
Data Segment
SS
Stack Segment
ES
Extra Segment
DS: E000
CS: B300
SS: 7000
ES: 5D27
Data Group
8 7
AX
AH
AL
Accumulator
BX
BH
BL
Base
CX
CH
CL
Counter
DX
DH
DL
Data
15
SP
Stack Pointer
BP
Base Pointer
SI
Source Index
DI
Destination Index
Index Registers
Addressing Modes
When a Microprocessor executes an instruction, it needs to
know where to get data and where to store results. Such
information is specified in the operand fields of the
instruction.
An instruction acts on any number of operands. The way an
instruction accesses its operands is called its Addressing
modes
Operand is data on which microprocessor operates
Operands : in Registers, Memory, I/O ports, and within
Instruction
Operands types
Implicit
Explicit
Both Implicit and Explicit
Addressing Modes
1.
Implicit addressing
The data value/data address is implicitly associated with the
instruction.
Addressing Modes
3.
Addressing Modes
4.
Addressing Modes
4. Memory addressing modes (Contd)
b. Indirect addressing mode
I. Register indirect addressing mode
Offset address of memory location is specified in the
register [BX] or [SI] or [DI]
The default segment is either DS or ES
Offset Address = [BX] / [SI] / [DI]
Examples: MOV CX, [SI]
Addressing Modes
4. Memory addressing modes (Contd)
II. Indexed addressing mode
Addressing Modes
4. Memory addressing modes (Contd)
III. Register Relative addressing mode
Data is available at an effective address formed by
adding an 8-bit or 16-bit displacement with content of
any registers
Effective Address = [SI] / [DI] / [BX] / [BP] + 8/16-bit
displacement
Examples: ADD DL, 99h[DI] or ADD DL, [99h+DI]
MOV AH, ES:6500h[SI]
Addressing Modes
4. Memory addressing modes (Contd)
IV. Based Indexd addressing mode
Addressing Modes
4. Memory addressing modes (Contd)
V. Relative Based Indexed addressing mode
Effective address of the memory location is obtained by
adding base register content i.e. [BX] or [BP], index register
i.e. [SI] or [DI] along with 8/16-bit displacement
Effective Address = [BX] / [BP] + [SI] / [DI] + 8/16-bit
displacement
Examples: MOV DL, 12h[SI][BX]
[SI+BX+12h]
or
MOV DL,
Addressing Modes
5. I/O port addressing
8086 can be interfaced to 8/16-bit I/O devices using either
I/O mapped I/O or memory-mapped I/O.
I/O mapped I/O uses the instructions IN and OUT
8086 can transfer 8/16-bit data to or from a peripheral
device
All I/O transfer between the 8086 and the peripheral devices
take place via AL for 8-bit ports and AX for 16-bit ports.
The I/O port addressing can be done either directly or
indirectly as follows:
a. Direct port addressing
b. Indirect port addressing
Addressing Modes
5.
a.
Instruction Format
General Format of Instructions
Label: Opcode Operand1, Operand2
; Comment
CONV
PROC NEAR
AND AL, OFH
CMP AL, 0AH
JC ADD30
ADD AL, 07
ADD30: ADD AL, 30H
RET
CONV ENDP
END Start
Start:
Check
PROC NEAR
MOV CX, 8
MOV AL, Num
MOV BL, 0
UP: ROR AL, 1
RLC BL, 1
Exit:
Check
LOOP UP
MOV Res, 5555H
CMP BL, NUM
JE Exit
MOV Res, 0AAAAH
RET
ENDP
END Start
Start:
.model small
.stack 20
.data
BCD_Num DB 3Fh
Hex_Num DW ?
.code
MOV AX, @DATA
MOV DS, AX
LEA SI, BCD_Num
LEA DI, Hex_Num
CALL BCD_to_HEX
INT 3
BCD_to_HEX
Check
PROC NEAR
MOV AL, [SI]
MOV BL, AL
AND BL, 0FH
MOV CL, 4
ROR AL, CL
AND AL, 0FH
MOV DL, 0AH
MUL DL
ADD AL, BL
MOV [DI], AL
RET
ENDP
END Start
Start:
.model small
.stack 20
.data
Num DB 3Fh
Res DW ?
.code
MOV AX, @DATA
MOV DS, AX
MOV BL, Num
MOV BH, 0
PUSH BX
CALL Square
POP BX
MOV Res, BX
INT 3
Square
Square
PROC NEAR
POP AX
MUL AL
PUSH AX
RET
ENDP
END Start