8086 CPU Complete Tutorials
8086 CPU Complete Tutorials
MICROPROCESSOR
8086 Microprocessor
8086 Features
The address refers to a byte in memory. In the 8088, these bytes come in on
the 8-bit data bus. In the 8086, bytes at even addresses come in on the low
half of the data bus (bits 0-7) and bytes at odd addresses come in on the upper
half of the data bus (bits 8-15).
The 8086 can read a 16-bit word at an even address in one operation and at an
odd address in two operations. The 8088 needs two operations in either case.
Data Bus
Data Registers
Control Arithmetic Status Memory
Unit Logic Unit Flags
Address Registers
Address Bus
Intel 16-bit Registers
General Purpose Index
AH AL
BP
AX
SP
BH BL
BX
SI
CH CL
DI
CX
DH DL
DX Segment
CS
Flags DS
IP ES
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 16-bit ALU.
The BIU fetches instructions using the CS and IP, written CS:IP, to contract
the 20-bit address. Data is fetched using a segment register (usually the DS)
and an effective address (EA) computed by the EU depending on the
addressing mode.
The EU contains the following 16-bit registers:
AX - the Accumulator
BX - the Base Register
CX - the Count Register
DX - the Data Register
SP - the Stack Pointer \ defaults to stack segment
BP - the Base Pointer /
SI - the Source Index Register
DI - the Destination Register
The AX, BX, CX, and DX registers can be considers as two 8-bit registers, a
High byte and a Low byte. This allows byte operations and compatibility with
the previous generation of 8-bit processors, the 8080 and 8085. 8085 source
code could be translated in 8086 code and assembled. The 8-bit registers are:
AX --> AH,AL
BX --> BH,BL
CX --> CH,CL
DX --> DH,DL
Registers
8086 Programmer’s Model
ES Extra Segment
BIU registers
(20 bit adder) CS Code Segment
SS Stack Segment
DS Data Segment
IP Instruction Pointer
EU registers AX AH AL Accumulator
BX BH BL Base Register
CX CH CL Count Register
DX DH DL Data Register
SP Stack Pointer
BP Base Pointer
SI Source Index Register
DI Destination Index Register
FLAGS
8086/88 internal registers 16 bits (2 bytes each)
• Registers
– Registers are in the CPU and are referred to by specific names
– Data registers
• Hold data for an operation to be performed
• There are 4 data registers (AX, BX, CX, DX)
– Address registers
• Hold the address of an instruction or data element
• Segment registers (CS, DS, ES, SS)
• Pointer registers (SP, BP, IP)
• Index registers (SI, DI)
– Status register
• Keeps the current status of the processor
• On an IBM PC the status register is called the FLAGS register
– In total there are fourteen 16-bit registers in an 8086/8088
Data Registers: AX, BX, CX, DX
• CX
– Count register
– Used as a loop counter
– Used in shift and rotate operations
• DX
– Data register
– Used in multiplication and division
– Also used in I/O operations
Pointer and Index Registers
F0000
E0000 8000:FFFF
D0000
C0000
B0000
A0000
one segment
90000
80000
70000
60000
8000:0250
50000
0250
40000
30000 8000:0000
20000
10000
seg ofs
00000
Intel
Adder
Offset: 0000000000101001
4000H
CS: 0400H
IP 0056H 4056H
CS:IP = 400:56
Logical Address
Memory
0400 0
Segment Register
Offset + 0056
Physical or 04056H
0FFFFFH
Absolute Address
The offset is the distance in bytes from the start of the segment.
The offset is given by the IP for the Code Segment.
Instructions are always fetched with using the CS register.
05C00H
DS: 05C0
05C50H
SI 0050 DS:EA
Memory
05C0 0
Segment Register
Offset + 0050
0A00 0A000H
SS:
0A100H
SP 0100 SS:SP
Memory
0A00 0
Segment Register
Offset + 0100
0FFFFFH
Physical Address 0A100H
Carry flag
Overflow
Direction Parity flag
Trap Zero
Sign
6 are status flags
3 are control flag
Flag Register
• Conditional flags:
– They are set according to some results of arithmetic operation. You do
not need to alter the value yourself.
• Control flags:
– Used to control some operations of the MPU. These flags are to be set
by you in order to achieve some specific purposes.
Flag O D I T S Z A P C
1
Bit no. 15 14 13 12 11 9 8 7 6 5 4 3 2 1 0
0
MOV AX,1
MOV BX,AX
register immediate
3F03 - 80x86 assembler
• Typical addressing modes
– Absolute address mode
MOV AX,[0200]
MOV AX,[BX]
MOV DI,4
MOV AX,[0200+DI]
MOV BX,0200
MOV DI,4
MOV AX,[BX+DI]
MOV BX,[DI] 56 02
MOV AX,[BX]
BX
0250 0256
The following signals now come from the 8288: ALE, DT/R’, DEN, and INTA’.
The advanced commands become active earlier in the cycle to give devices
an earlier indication of a write operation.
IV-1
8086 Maximum Mode
When in the maximum mode, the 8086/8088 has 3 status lines that are
connected to the 8288 and provide it with the information it needs to
generate the system bus signals. The information provided by the status
bits is as follows.
IV-2
Direct Memory Access - DMA
DMA allows data to go between memory and a peripheral, such as a disk
drive, without going through the cpu.
The DMA controller takes over the address bus, data bus, and control bus.
The 8237A DMA Controller is a commonly used device and is in the IBM PC.
Figure 11-4 is a simplified block diagram showing the use of a DMA controller.
For example, to read a disk file the following operations occur.
IV-4
Memory
Terminology
Volatile - data is lost when power is turned off.
Nonvolatile - retains data when powered off.
Random Access - all data locations accessed in the same amount of time.
Sequential Access - data accessed in varying amounts of time, e.g., tape.
Examples
VOLATILE NONVOLATILE
Static RAM ROM, PROM, EPROM, EEPROM, FLASH
Dynamic RAM Disk, tape
Magnetic core, magnetic bubble
IV-6
Interface 8086 to 6116 static RAM
8086 A0, BHE*
6116 (2K x8)
21 A(11-1)
20 A(10-0)
A
____ Latch D(7-0)
D(7-0) __ low byte
BHE
A(19-12) R/W
ALE
OE*
(even)
D 16
CS*
Addr
Decoder RAMCS*
__ A0 A(11-1) A(10-0)
MEM* D(7-0)
M/IO
___ D(15-8) __ hi byte
WR R/W
___ (odd)
OE*
RD CS*
BHE*
READY Wait
State
RLH - Fall 1997 Gen 47
Introduction
to
8086
Assembly Language
Programming
What Is Assembly Language
• Machine-Specific Programming Language
– one-one correspondence between statements
and native machine language
– matches machine instruction set and
architecture
• IBM-PC Assembly Language
– refers to 8086, 8088, 80186, 80286, 80386,
80486, and Pentium Processors
What Is An Assembler?
• Systems Level Program
– translates assembly language source code to
machine language
• object file - contains machine instructions, initial
data, and information used when loading the
program
• listing file - contains a record of the translation
process, line numbers, addresses, generated code
and data, and a symbol table
Why Learn Assembly
Language?
• Learn how a • Allows creation of
processor works small and efficient
• Understand basic programs
computer architecture • Allows programmers
• Explore the internal to bypass high-level
representation of data language restrictions
and instructions • Might be necessary to
• Gain insight into accomplish certain
hardware concepts operations
Data Representation
• Binary 0-1 • Word - 16 Bits
– represents the state of – Each architecture may
electronic components define its own
used in computer “wordsize”
systems • Doubleword - 32 Bits
• Bit - Binary digit • Quadword - 64 Bits
• Byte - 8 Bits • Nybble - 4 Bits
– smallest addressable
memory location (on
the IBM-PC)
Numbering Systems
• Binary - Base 2 • Raw Binary format
– 0, 1 – All information is
• Octal - Base 8 coded for internal
storage
– 0, 1, 2, … 7
– Externally, we may
• Decimal - Base 10 choose to express the
– 0, 1, 2, …, 9 information in any
• Hexadecimal (Hex) numeration system, or
in a decoded form
– 0, 1, …, 9, A, B, …, F using other symbols
Decoding a Byte
• Raw • Machine Instruction
– 01010000b – Push AX
• Hex • ASCII Character code
– 50h – ‘P’
• Octal • Integer
– 1208 – 80 (eighty)
• Decimal • BCD
– 80d – 50 (fifty)
• Custom code ???
Machine Language
• A language of numbers, called the
Processor’s Instruction Set
– The set of basic operations a processor can
perform
• Each instruction is coded as a number
• Instructions may be one or more bytes
• Every number corresponds to an
instruction
Assembly Language vs Machine
Language Programming
These fields are separated by White Space (tab, blank, \n, etc.)
8086 Instruction - Example
Label Operator Operand[s] ;Comment
Label - INIT:
Operator - mov
Operands - ax and bx
Comment - alphanumeric string between ; and \n
NEG ;Negate
NOT ;Logical NOT
OR ;Logical inclusive OR
RCL ;Rotate through Carry Left
RCR ;Rotate through Carry Right
ROL ;Rotate Left
ROR ;Rotate Right
SAR ;Shift Arithmetic Right
SBB ;Subtract with Borrow
SCAS ;Scan memory at DI compared to AX
SHL/SAL ;Shift logical/Arithmetic Left
SHR ;Shift logical Right
SUB ;Subtract
TEST ;AND function to flags
XLAT ;Translate byte to AL
XOR ;Logical Exclusive OR
x86 Instruction Set Summary
(Control/Branch Cont.)
CALL ;Call
CLC ;Clear Carry
CLD ;Clear Direction
CLI ;Clear Interrupt
ESC ;Escape (to external device)
HLT ;Halt
INT ;Interrupt
INTO ;Interrupt on Overflow
IRET ;Interrupt Return
JB/JNAE ;Jump on Below/Not Above or Equal
JBE/JNA ;Jump on Below or Equal/Not Above
JCXZ ;Jump on CX Zero
JE/JZ ;Jump on Equal/Zero
JL/JNGE ;Jump on Less/Not Greater or Equal
JLE/JNG ;Jump on Less or Equal/Not Greater
JMP ;Unconditional Jump
JNB/JAE ;Jump on Not Below/Above or Equal
JNBE/JA ;Jump on Not Below or Equal/Above
JNE/JNZ ;Jump on Not Equal/Not Zero
JNL/JGE ;Jump on Not Less/Greater or Equal
x86 Instruction Set Summary
(Control/Branch)
JNLE/JG ;Jump on Not Less or Equal/Greater
JNO ;Jump on Not Overflow
JNP/JPO ;Jump on Not Parity/Parity Odd
JNS ;Jump on Not Sign
JO ;Jump on Overflow
JP/JPE ;Jump on Parity/Parity Even
JS ;Jump on Sign
LOCK ;Bus Lock prefix
LOOP ;Loop CX times
LOOPNZ/LOOPNE ;Loop while Not Zero/Not Equal
LOOPZ/LOOPE ;Loop while Zero/Equal
NOP ;No Operation (= XCHG AX,AX)
REP/REPNE/REPNZ ;Repeat/Repeat Not Equal/Not Zero
REPE/REPZ ;Repeat Equal/Zero
RET ;Return from call
SEG ;Segment register
STC ;Set Carry
STD ;Set Direction
STI ;Set Interrupt
TEST ;AND function to flags
WAIT ;Wait
Assembler Directives
.data
dos_print EQU 9 ;define a constant
strng DB 'Hello World',13,10,'$' ;Define the character string
.code
START: mov ax, SEG strng ;ax <-- data segment start address
mov ds, ax ;ds <-- initialize data segment register
mov ah, dos_print ;ah <-- 9 DOS 21h string function
mov dx,OFFSET strng ;dx <-- beginning of string
int 21h ;DOS service interrupt
mov ax, 4c00h ;ax <-- 4c DOS 21h program halt function
int 21h ;DOS service interrupt
END START
Program Statements
name operation operand(s) comment
• Operation is a predefined or reserved
word
– mnemonic - symbolic operation code
– directive - pseudo-operation code
• Space or tab separates initial fields
• Comments begin with semicolon
• Most assemblers are not case sensitive
Program Data and Storage
• Pseudo-ops to define • These directives
data or reserve require one or more
storage operands
– DB - byte(s) – define memory
– DW - word(s) contents
– DD - doubleword(s) – specify amount of
– DQ - quadword(s) storage to reserve for
run-time data
– DT - tenbyte(s)
Defining Data
• Numeric data values • A list of values may
– 100 - decimal be used - the
– 100B - binary following creates 4
– 100H - hexadecimal consecutive words
– '100' - ASCII DW 40CH,10B,-13,0
– "100" - ASCII • A ? represents an
• Use the appropriate uninitialized storage
DEFINE directive location
(byte, word, etc.) DB 255,?,-128,'X'
Naming Storage Locations
• Names can be • ANum refers to a byte
associated with storage location,
storage locations initialized to FCh
ANum DB -4 • The next word has no
DW 17 associated name
ONE
UNO DW 1 • ONE and UNO refer
X DD ? to the same word
• These names are called • X is an unitialized
variables doubleword
Arrays
• Any consecutive storage locations of the
same size can be called an array
X DW 40CH,10B,-13,0
Y DB 'This is an array'
Z DD -109236, FFFFFFFFH, -1, 100B
• Components of X are at X, X+2, X+4, X+8
• Components of Y are at Y, Y+1, …, Y+15
• Components of Z are at Z, Z+4, Z+8, Z+12
DUP
• Allows a sequence of storage locations to
be defined or reserved
• Only used as an operand of a define
directive
DB 40 DUP (?)
DW 10h DUP (0)
DB 3 dup ("ABC")
Word Storage