8086 Microprocessor
8086 Microprocessor
The Intel 8086 is a 16 bit Microprocessor that is intended to be used as the CPU in a
Microcomputer.
The term 16 bit means that it's ALU, its internal registers, and most of its instructions
are designed to work with 16 bit binary words.
The 8086 has a 16 bit data bus, so it can read data from or write data to memory and
ports either 16 bits or 8 bits at a time.
The 8086 has a 20 bit address bus, so it can address 2 20 or 1,048576 memory
locations.
If the first byte of a word is at an even address, the 8086 can read the entire word in
one operation.
If the first byte of the word is at an odd address, the 8086 will read the first byte with
one bus operation and the second byte with another bus operation
The main point here is that if the first byte of a 16 bit word is at an even address, the
8086 can read the entire word in one operation
The Intel 8088 has the same arithmetic logic unit, the same registers and the same
instruction set as the 8086.
The 8088 also has a 20 bit address bus, so it can address any one of 1,048,576 bytes in
memory.
The 8088 has an 8 bit data bus, so it can only read data from or write data to memory
and ports 8 bits at a time.
To read a 16 bit word from two successive memory locations, the 8088 will always have
to do two read operations.
In addition to 16 bit CPU, the 80186 and 80188 each have programmer peripheral
devices integrated in the same package.
www.ncitians.com/downloads/
8086 INTERNAL ARCHITECTURE
The 8086 CPU is divided into two independent functional parts : BIU (Bus Interface
Unit) and EU (Execution Unit)
The BIU send out address, fetches instructions from memory, reads data from ports and
memory, and writes data to ports and memory.
In other words BIU handles all transfers of data and addresses on the buses for the
execution unit.
The EU of the 8086 tells the BIU where to fetch the instructions and data from, decodes
instructions and executes instructions.
www.ncitians.com/downloads/
A.THE EXECUTION UNIT
The EU contains control circuitry which directs internal operations.
The EU has a 16 bit ALU which can add subtract, ND, OR, increment, decrement,
complement or shift binary numbers.
The EU has eight general purpose registers, labeled AH, AL, BH, BL, CH, CL, DH and DL.
These registers can be used individually for temporary storage of 8 bit data.
It has some features that the other general purpose registers do not have.
Certain pairs of these general purpose registers can be used together to store 16 bit
words.
The acceptable register pairs are AH and AL,BH and BL,CH and CL,DH and DL
The AH-AL pair is referred to as the AX register, the BH-BL pair is referred to as the BX
register, the CH-CL pair is referred to as the CX register, and the DH-DL pair is referred
to as the DX register.
AX = Accumulator Register
BX = Base Register
CX = Count Register
DX = Data Register
2. FLAG REGISTER
A Flag is a flip-flop which indicates some condition produced by the execution of an
instruction or controls certain operations of the EU.
Figure below show shows the location of the nine flags in the flag register.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
U U U U OF DF IF TF SF ZF U AF U PF U CF
U = UNDEFINED
CONDITIONAL FLAGS
CF = CARRY FLAG [Set by Carry out of MSB]
www.ncitians.com/downloads/
PF = PARITY FLAG [Set if Result has even parity]
AF= AUXILIARY CARRY FLAG FOR BCD
ZF = ZERO FLAG [Set if Result is 0]
SF = SIGN FLAG [MSB of Result]
OF = OVERFLOW FLAG
CONTROL FLAG
TF = SINGLE STEP TRAP FLAG
IF = INTERRUPT ENABLE FLAG
DF = STRING DIRECTION FLAG
The six conditional flags in this group are the CF,PF,AF,ZF,SF and OF
The three remaining flags in the Flag Register are used to control certain operations of
the processor.
The six conditional flags are set or reset by the EU on the basis of the result of some
arithmetic or logic operation.
The Control Flags are deliberately set or reset with specific instructions you put in your
program.
3. POINTER REGISTERS
The 16 bit Pointer Registers are IP,SP and BP respectively
BP can also be combined with DI and SI as a base register for special addressing.
4. INDEX REGISTERS
The 16 bit Index Registers are SI and DI
1. SEGMENT REGISTERS
1.1 CS REGISTER
It contains the starting address of a program's code segment.
This segment address plus an offset value in the IP register indicates the address of an
instruction to be fetched for execution
For normal programming purpose, you need not directly reference this register.
1.2 DS REGISTER
It contains the starting address of a program's data segment
This address plus an offset value in an instruction causes a reference to a specific byte
location in the data segment.
1.3 SS REGISTER
Permits the implementation of a stack in memory
It stores the starting address of a program's stack segment the SS register.
This segment address plus an offset value in the Stack Pointer (SP) register indicates
the current word in the stack being addressed.
1.4 ES REGISTER
It is used by some string operations to handle memory addressing.
For each instruction that executes, the processor changes the offset value in IP so that
IP in effect directs each step of execution.
3. THE QUEUE
The BIU Stores prefetched bytes in First in First out register set called a queue.
When the EU is ready for its next instruction, it simply reads the instruction bytes for
the instruction from the queue in the BIU.
This is much faster than sending out an address to the system memory and waiting for
memory to send back the next instruction bytes or bytes.
Fetching the next instruction while the current instruction executes is called pipeling.
8086 MEMORY ORGANIZATION
1. INTRODUCTION
The Intel 8086 is a 16 bit Microprocessor that is intended to be used as the CPU in a
Microcomputer.
www.ncitians.com/downloads/
The 8086 has a 20 bit address bus so it can address any one of 2 20 or 1,048,576
memory locations.
Each of the 1,048,576 memory address of the 8086 represents a byte-wide location.
If the first byte of a word is at an even address, the 8086 can read the entire word in
one operation.
If the first byte of a word is at an odd address, the 8086 will read the first byte with one
bus cycle and the second byte with another bus cycle.
FFFFFH FFFFEH
00003H 00002H
00001H 00000H
www.ncitians.com/downloads/
2. ACCESSING DATA IN MEMORY
An important point here is that an 8086 always stores the low byte of word in lower
address and stores high byte of word in higher address.
MOV AX,[437AH]
Assume DS=2000H
AX
52 2437BH AH AL
02 2437AH
3. SEGMENTED MEMORY
The 8086 BIU sends out 20 bit address so it can address any of 2 20 or 1,048,576 bytes
in memory.
However at any given time the 8086 works with only four 65536 bytes (64 Kbyte)
segment within this 1,048,576 byte (1 Mbyte) Range
Four segments are : Code Segment, Stack Segment, Data Segment and Extra Segment
Four segment registers in BIU are used to hold the upper 16 bits of the starting address
of 4 memory segments that the 8086 is working with at a particular time.
The 4 segment registers are code segment register (CS), stack segment register (SS),
data segment register (DS) and the extra segment register (ES).
For small programs which do not need all 64 Kbytes in each segment can overlap.
For example, the code segment holds the upper 16 bits of the starting address for the
segment from which the BIU is currently fetching instruction code bytes.
The BIU always inserts zero for the lowest 4 bits of the 20 bit starting address.
www.ncitians.com/downloads/
If the code segment register contains 348A H then the code segment will start at
address 348A0 H
A 64 Kbytes segment can be located anywhere within the 1 Mbyte address space, but
the segment will always start at an address with zeros in the lowest 4 bits.
Intel designed the 8086 family devices to access memory using the segment: offset approach
rather than accessing memory directly with 20 bit. The advantages are listed below.
The segment: offset scheme requires only a 16 bit number to represent the base
address for a segment and only a 16 bit offset to access any location in a segment. This
means that 8086 has to manipulate and store only 16 bit quantities instead of 20 bit
quantities.
This makes easier interface with 8 and 16 bit wide memory boards and with 16 bit
registers in the 8086.
It allows programs written to function in the real mode to operate in protected mode.
Segmentation also makes easy to keep user's program and data separate from one
another and segmentation makes it easy to switch from one user's program to another
user's program.
The segment: offset scheme introduces complexity in hardware and software design.
www.ncitians.com/downloads/
ADDRESSING MODES
The different ways in which a processor can access data are referred to as its
addressing modes.
It is carried out with 8 bit registers AH,AL,BH,BL,CH,CL,DH & DL or with 16 bit registers
AX,BX,CX,DX,SP,BP,SI and DI.
Never mix an 8 bit register with a 16 bit register i.e. MOV AX,BL
EXAMPLES
MOV AL,BL : Copys BL into AL
MOV ES,DS : Copys DS into ES
MOV AX,CX : Copys CX into AX
The term immediate implies that the data immediately follow the hexadecimal opcode
in the memory.
EXAMPLES
MOV AL,90 : Copys 90 into AL
MOV AX,1234H : Copys 1234H into AX
MOV CL,10000001B : Copys 100000001 binary value into CL
www.ncitians.com/downloads/
3. DIRECT ADDRESSING MODE
In this scheme, the address of the data is defined in the instruction itself.
MEMORY LOCATION
11234 H
EXAMPLES
MOV AL,[1234H] : Copys the byte content of data segment memory location
11234H into AL.
MOV AL, NUMBER : Copys the byte content of data segment memory location
NUMBER into AL.
The Index and Base registers are used to specify the address of data.
The data segment is used by default with register indirect addressing or any other
addressing mode that uses BX,DI or SI to address memory. If BP register addresses
memory, the stack segment is used by default.
MEMORY LOCATION
10300H
EXAMPLES
MOV CX,[BX] : Copys the word contents of the data segment memory
location addressed by BX into CX.
MOV [DI],[BX] : Memory to Memory moves are not allowed except with
string instructions.
5. BASE PLUS INDEX ADDRESSING MODE
www.ncitians.com/downloads/
Base plus index addressing is similar to indirect addressing because it indirectly
addresses memory data
This type of addressing uses one base register (BP or BX) and one Index Register (DI or
SI) to indirectly address memory.
MEMORY LOCATION
10500H
EXAMPLES
MOV CX,[BX+DI] : Copys the word contents of the data segment memory
location addressed by BX plus DI into CX.
MOV CH,[BP+SI] : Copys the byte contents of the stack segment memory
location addressed by BP plus SI into CH.
In this case, the data in a segment of memory are addressed by adding the
displacement to the content of base or an index register (BP,BX ,DI or SI).
MEMORY LOCATION
10304H
EXAMPLES
MOV ARRAY[SI],BL : Copys BL into the data segment memory location
addressed by ARRAY plus SI.
The base relative plus index addressing mode is similar to the base plus index
www.ncitians.com/downloads/
addressing mode but it adds a displacement to form a memory address.
Transfers a byte or word between a register and the memory location addressed by a
base and an index register plus a displacement.
MEMORY LOCATION
10505H
EXAMPLES
MOV LIST[BP+DI],CL : Copys CL into the stack segment memory location
addressed by the sum of LIST, BP and DI
www.ncitians.com/downloads/
INSTRUCTION SETS
INSTRUCTIONS COMMENTS
MOV Copy byte or word from specified source to
specified destination.
MOV Destination,Source
MOV CX,04H
PUSH Copy specified word to top of stack.
PUSH Source
PUSH BX
POP Copy word from top to stack to specified
location.
POP Destination
POP AX
XCHG Exchange word or byte.
XCHG Destination,Source
XCHG AX,BX
XLAT Translate a byte in AL using a table in memory.
It first adds AL + BX to form memory address.
It then copys the content into AL
INSTRUCTIONS COMMENTS
IN Copy a byte or word from specified port to
accumulator.
IN AX,Port_Addr
IN AX,34H
INSTRUCTIONS COMMENTS
LEA Load effective address of operand into
specified register.
LEA Register,Source
LEA BX,PRICE
LDS Load DS register and other specified register
from memory.
LDS Register,Source
LDS BX,[4326H]
LES Load ES register and other specified register
from memory.
www.ncitians.com/downloads/
1.4 FLAG TRANSFER INSTRUCTIONS
INSTRUCTIONS COMMENTS
LAHF Copy to AH with the low byte of the flag
register.
SAHF Stores AH register to low byte of flag register.
PUSHF Copy flag register to top of stack.
POPF Copy word at top of stack to flag register.
www.ncitians.com/downloads/
2. ARITHMETIC INSTRUCTIONS
INSTRUCTIONS COMMENTS
ADD Add specified byte to byte or word to word.
ADD Destination,Source
ADD AL,74H
ADC Add byte + byte + carry flag
Add word+word + carry flag
ADC Destination,Source
ADC CL,BL
INC Increment specified byte or word by 1.
INC Register
INC CX
AAA ASCII adjust after addition.
DAA Decimal adjust after addition.
INSTRUCTIONS COMMENTS
SUB Subtract byte from byte or word from word.
SUB Destination,Source
SUB CX,BX
SBB Subtract byte and carry flag from byte.
Subtract word and carry flag from word.
SBB Destination,Source
SBB CH,AL
DEC Decrement specified byte or word by 1.
DEC Register
DEC CX
NEG Form 2's complement.
NEG Register
NEG AL
CMP Compare two specified bytes or words.
CMP Destination,Source
CMP CX,BX
CF ZF SF
CX = BX 0 1 0
CX > BX 0 0 0
CX < BX 1 0 1
www.ncitians.com/downloads/
2.3 MULTIPLICATION INSTRUCTIONS
INSTRUCTIONS COMMENTS
MUL Multiply unsigned byte by byte or unsigned
word by word.
MUL Source
MUL CX
IMUL Multiply signed byte by byte or signed word by
word.
IMUL Source
IMUL CX
AAM ASCII adjust after multiplication.
It converts packed BCD to unpacked BCD.
INSTRUCTIONS COMMENTS
DIV Divide unsigned word by byte
Divide unsigned word double word by byte.
DIV Source
DIV BL
DIV CX
AAD ASCII adjust before division
BCD to binary convert before division.
www.ncitians.com/downloads/
3.1 LOGICAL INSTRUCTIONS
INSTRUCTIONS COMMENTS
NOT Invert each bit of a byte or word.
NOT Destination
NOT BX
AND AND each bit in a byte/word with the
corresponding bit in another byte or word.
AND Destination,Source
AND BH,CL
OR OR each bit in a byte or word with the
corresponding bit in another byte or word.
OR Destination,Source
OR AH,CL
XOR XOR each bit in a byte or word with the
corresponding bit in another byte or word.
XOR Destination,Source
XOR CL,BH
TEST AND operands to update flags, but don't
change the operands.
TEST Destination,Source
TEST AL,BH
INSTRUCTIONS COMMENTS
SHL/SAL Shift Bits of Word or Byte Left, Put Zero(s) in
LSB.
SAL Destination,Count
SHL Destination,Count
CFMSBLSB0
SHR Shift Bits of Word or Byte Right, Put Zero(s) in
MSB.
SHR Destination,Count
0MSBLSBCF
SAR Shift Bits of Word or Byte Right, Copy Old MSB
into New MSB.
SAR Destination,Count
MSBMSBLSBCF
INSTRUCTIONS COMMENTS
ROL Rotate Bits of Byte or Word Left,MSB to LS and
to CF.
ROR Rotate Bits of Byte or Word Right,LSB to MSB
and to CF.
RCL Rotate Bits of Byte or Word Left,MSB to CF and
CF to LSB.
RCR Rotate Bits of Byte or Word Right,LSB TO CF
and CF TO MSB.
www.ncitians.com/downloads/
4. PROGRAM EXECUTION TRANSFER INSTRUCTIONS
INSTRUCTIONS COMMENTS
CALL Call a Subprogram/Procedure.
INSTRUCTIONS COMMENTS
JA/JNBE Jump if Above/Jump if Not Below or Equal.
www.ncitians.com/downloads/
4.3 ITERATION CONTROL INSTRUCTIONS
INSTRUCTIONS COMMENTS
LOOP Loop Through a Sequence of Instructions Until
CX=0.
INSTRUCTIONS COMMENTS
INT
INT0 Interrupt Program Execution if OF=1
INSTRUCTIONS COMMENTS
STC Set Carry Flag CF to 1.
INSTRUCTIONS COMMENTS
NOP No Action Except Fetch and Decode.
6 STRING INSTRUCTIONS
INSTRUCTIONS COMMENTS
REP Repeat Instruction Until CX=0.
www.ncitians.com/downloads/
ASSEMBLY LANGUAGE PROGRAMMING
INTRODUCTION
Assembly Language uses two, three or 4 letter mnemonics to represent each instruction
type.
Low level Assembly Language is designed for a specific family of Processors : the symbolic
instruction directly relate to Machine Language instructions one for one and are assembled
into machine language
They then translate Assembly Language program to machine language so that it can be
loaded into memory and run.
A Program written in Assembly Language requires considerably less Memory and execution
time than that of High Level Language.
Assembly Language gives a programmer the ability to perform highly technical tasks.
Resident Programs (that resides in memory while other programs execute) and Interrupt
Service Routine (that handles I/P and O/P) are almost always developed in Assembly
Language.
Provides more control over handling particular H/W requirements.
Assembly language statements are usually written in a standard form that has 4 fields.
Labels are only inserted when they are needed so it is an optional field.
The opcode field of the instruction contains the mnemonics for the instruction to be
performed
The operand field of the statement contains the data, the memory address, the port
address or the name of the register on which the instruction is to be performed.
The final field in an assembly language statement is the comment field which starts with
semicolon. It forms a well documented program.
www.ncitians.com/downloads/
ASSEMBLY LANGUAGE PROGRAM DEVELOPMENT TOOLS
1. EDITOR
An Editor is a Program which allows you to create a file containing the Assembly Language
statements for your Program.
2. ASSEMBLER
3. LINKER
A Linker is a Program used to join several files into one large .obj file. It produces .exe file
so that the program becomes executable.
4. LOCATOR
A Locator is a program used to assign the specific address of where the segment of object
code are to be loaded into memory.
5. DEBUGGER
A Debugger is a program which allows you to load your .obj code program into system
memory, execute program and troubleshoot.
It allows you to look at the content of registers and memory locations after your program
runs.
6. EMULATOR
It is used to test and debug the hardware and software of an external system such as the
prototype of a Microprocessor based system.
www.ncitians.com/downloads/
ASSEMBLY LANGUAGE PROGRAM FEATURES
#PROGRAM COMMENTS
The use of Comments throughout a program can improve its clarity, especially in Assembly
Language.
EXAMPLE
MOV AX, BX ; Adds the Content of BX with AX
#RESERVED WORDS
Instructions : MOV, ADD
Directives : END,SEGMENT
Operators : FAR,OFFSET
Predefined Symbols : @DATA
#IDENTIFIERS
An Identifier (or symbol) is a name that you apply to an item in your program that you
expect to reference. The two types of identifiers are NAME and LABEL.
MAIN PROC
A20: MOV AL,BL
#STATEMENTS
An Assembly Program consists of a set of statements. The two types of statements are:
1. INSTRUCTION
Instructions such as MOV & ADD which the Assembler translates to Object Code.
2. DIRECTIVES
Directives tell the Assembler to perform a specific action, such as define a data item
etc.
PAGE 60,80
TITLE "ALP TO PRINT FACTORIAL NO"
MAIN PROC
……………………………
…………………………..
…………………………..
…………………………… ; INSTRUCTION SETS
…………………………..
……………………………
…………………………..
……………………………
MAIN ENDP
END MAIN
www.ncitians.com/downloads/
DIRECTIVES
Assembly Language supports a number of statements that enable to control the way in
which a source program assembles and lists. These Statements are called Directives.
They act only during the assembly of a program and generate no machine executable code.
The most common Directives are PAGE, TITLE, PROC, and END.
# PAGE DIRECTIVE
The PAGE Directive helps to control the format of a listing of an assembled program.
It is optional Directive.
At the start of program, the PAGE Directive designates the maximum number of lines to list
on a page and the maximum number of characters on a line.
Its format is
PAGE [LENGTH],[WIDTH]
Omission of a PAGE Directive causes the assembler to set the default value to PAGE 50,80
# TITLE DIRECTIVE
The TITLE Directive is used to define the title of a program to print on line 2 of each page
of the program listing.
Its format is
TITLE [TEXT]
# SEGMENT DIRECTIVE
A Stack Segment defines stack storage, a data segment defines data items and a code
segment provides executable code.
The format (including the leading dot) for the directives that defines the stack, data and
code segment are
.STACK [SIZE]
.DATA
………………. Initialize Data Variables
.CODE
The different models tell the assembler how to use segments to provide space and ensure
optimum execution speed.
www.ncitians.com/downloads/
The format of Memory Model Definition is
The Memory Model may be TINY, SMALL, MEDIUM, COMPACT, LARGE AND HUGE.
The Code Segment contains the executable code for a program, which consists of one or
more procedures, defined initially with the PROC Directive and ended with the ENDP
Directive.
#END DIRECTIVE
As already mentioned, the ENDP Directive indicates the end of a procedure.
An END Directive ends the entire Program and appears as the last statement.
Its Format is
#PROCESSOR DIRECTIVE
Most Assemblers assume that the source program is to run on a basic 8086 level.
As a result, when you use instructions or features introduced by later processors, you have
to notify the assemblers be means of a processor directive as .286,.386,.486 or .586
www.ncitians.com/downloads/
This directive may appear before the Code Segment.
EXAMPLE
DATAX DB 25
DATA EQU DATAX
MASM 6.0 introduced the .STARTUP and .EXIT Directive to simplify program initialization
and Termination.
.EXIT generates the INT 21H function 4ch instruction for exiting the Program.
www.ncitians.com/downloads/
DEFINING TYPES OF DATA
EXAMPLES
STRING DB 'HELLO WORLD'
NUM1 DB 10
NUM2 DB 90
DEFINITION DIRECTIVE
BYTE DB
WORD DW
DOUBLE WORD DD
FAR WORD DF
QUAD WORD DQ
TEN BYTES DT
EXAMPLES
DATAX DB 5 DUP(12) ; 5 Bytes containing hex 0c0c0c0c0c
DATA DB 10 DUP(?) ; 10 Words Uninitialized
1. CHARACTER STRINGS
Consequently DB is the conventional format for defining character data of any length
An Example is
DB 'Computer City'
DB "Hello World"
DB "St.Xavier's College"
2. NUMERIC CONSTANTS
;-------------------------------------------------------------
.MODEL SMALL
.STACK
.DATA
STRING DB 'HELLO WORLD $'
.CODE
;-------------------------------------------------------------
MAIN PROC
MOV AX,@DATA
MOV DS,AX ; Initialize the DATA Segment
;-------------------------------------------------------------
www.ncitians.com/downloads/
#SAMPLE 2
;-------------------------------------------------------------
.MODEL SMALL
.STACK
.DATA
VAL1 DB 89
VAL2 DB 10
MSG DB 'SUM OF 2 NUMBERS: $'
.CODE
;-------------------------------------------------------------
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AX,0
MOV AL,VAL1
ADD AL,VAL2
PUSH AX
;;;;;;;;;;;;;DISPLAY MESSAGE
LEA DX,MSG
MOV AH,09H
INT 21H
;;;;;;;;;;;;;END DISPLAY MESSAGE
POP AX
MOV DL,AH
MOV DH,AL
MOV AH,02H
INT 21H
MOV DL,DH
MOV AH,02H
INT 21H
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
;-------------------------------------------------------------
www.ncitians.com/downloads/
#SAMPLE 3
;-------------------------------------------------------------
.MODEL SMALL
.STACK
.DATA
.CODE
;-------------------------------------------------------------
MAIN PROC
MOV AX,@DATA
MOV DS,AX
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;INT 10H Function 06H : Scroll Up Screen
;AH=Function 06H
;AL=Number of lines to scroll,or 00H for full screen
;BH=Attribute value(color,blinking)
;CX=Strating row:column
;DX=Ending row :column
;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
;-------------------------------------------------------------
www.ncitians.com/downloads/
#SAMPLE 4
;-------------------------------------------------------------
.MODEL SMALL
.STACK
.DATA
.CODE
;-------------------------------------------------------------
MAIN PROC
MOV AX,@DATA
MOV DS,AX
;;;;;;;;;;;;;;;;;;;;;;;
;INT 10H Function 09H: Display Character
;AH=09H
;AL=ASCII Character
;BH=Page Number
;BL=Attribute or Pixel value.
;CX=Count
;;;;;;;;;;;;;;;;;;;;;;
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
;-------------------------------------------------------------
www.ncitians.com/downloads/