Chapter 03 8086
Chapter 03 8086
8086 Microprocessor
Introduction to 8086 Microprocessor
Features of 8086 microprocessor
• Intel 8086 is a widely used 16 bit microprocessor.
• The 8086 can directly address 1MB of memory.
• The internal architecture of the 8086 microprocessor is an example of register based
microprocessor and it uses segmented memory.
• It pre-fetches up to 6 instrucAon bytes from the memory and queues them in order to speed up
the instrucAon execuAon.
• It has data bus of width 16 bits and address bus of width 20 bits. So it always accesses a 16 bit
word to or from memory.
• The 8086 microprocessor is divided internally into two separate units which are Bus interface
unit (BIU) and the execuAon unit (EU).
• The BIU fetches instrucAons, reads operands and write results.
• The EU executes instrucAons that have already been fetched by BIU so that instrucAons fetch
overlaps with execuAon.
• A 16 bit ALU in the EU maintains the MP status and control flags, manipulates general register
and instrucAon operands.
8086 architecture
Bus Interface Unit(BIU) and its Components
• The BIU sends out addresses, fetches instructions from memory reads data from
memory or ports and writes data to memory or ports.
• So it handles all transfers of data and address on the buses for EU. It has main 2
parts instruction queue and segment registers.
• The BIU can store up to 6 bytes of instructions with FIFO (First in First Out)
manner in a register set called a queue.
• When EU is ready for next instruction, it simply reads the instruction from the
queue in the BIU. This is done in order to speed up program execution by
overlapping instruction fetch with execution. This mechanism is known as
pipelining.
• The BIU contains a dedicated address, which is used to produce 20 bit address.
• Four segment registers in the BIU are used to hold the upper 16 bits of the
starting address of four memory segments that the 8086 is working at a particular
time.
• These are code segment, data segment, stack segment and extra segment. The
8086’s 1 MB memory is divided into segments up to 64KB each.
Code segment register and instruction pointer (IP)
.................................
................................
.................................
................................
.................................
MAIN ENDP END MAIN
Direc8ve
• 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
DirecTves.
• They act only during the assembly of a program and generate no machine
executable code.
• The most common DirecTves are PAGE, TITLE, PROC, and END.
# PAGE DIRECTIVE
• The PAGE DirecTve helps to control the format of a lisTng of an assembled
program.
• It is opTonal DirecTve.
• At the start of program, the PAGE DirecTve 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 DirecTve 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.
• It is also optional Directive.
• Its format is
• TITLE [TEXT]
TITLE "PROGRAM TO PRINT FACTORIAL NO"
# SEGMENT DIRECTIVE
• The SEGMENT Directive defines the start of a segment.
• A Stack Segment defines stack storage, a data segment defines data
• items and a code segment provides executable code.
• MASM provides simplified Segment Directive.
• 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 Default Stack size is 1024 bytes.
• To use them as above, Memory Model initialization should be carried
out.
MEMORY MODEL DEFINTION
• The different models tell the assembler how to use segments to
provide space and ensure optimum execution speed.
• The format of Memory Model Definition is .MODEL [MODEL NAME]
• The Memory Model may be TINY, SMALL, MEDIUM, COMPACT, LARGE
AND HUGE.
THE PROC DIRECTIVE
• 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.
• Its Format is given as:
PROCEDURE NAME PROC ....................
...................
...................
PROCEDURE NAME ENDP
END DIRECTIVE
DATAX DB 25
DATA EQU DATAX
DEFINING TYPES OF DATA
2. NUMERIC CONSTANTS
• #BINARY #DECIMAL #HEXADECIMAL
• VAL1 DB 10101010B
• VAL1 DB 230
• VAL1 DB 23H
; Program to print hello world
;addiJon
Page 60, 132
TITLE Sum program to add two numbers.
.MODEL SMALL
.STACK 64
.DATA
NUM1 DW 3241 NUM 2 DW 572
Assembling
Assembling, Linking and Executing
1) Assembling:
• Assembling converts source program into object program if syntactically correct
and generates an intermediate .obj file or module.
• It calculates the offset address for every data item in data segment and every
instruction in code segment.
• A header is created which contains the incomplete address in front of the
generated obj module during the assembling.
• Assembler complains about the syntax error if any and does not generate the
object module.
• Assembler creates .obj .lst and .crf files and last two are optional files that can be
created at run time.
• For short programs, assembling can be done manually where the programmer
translates each mnemonic into the machine language using lookup table.
• Assembler reads each assembly instruction of a program as ASCII character and
translates them into respective machine code.
Assembler Types:
There are two types of assemblers:
a) One pass assembler:
• This assembler scans the assembly language program once and
converts to object code at the same time.
• This assembler has the program of defining forward references only.
• The jump instruction uses an address that appears later in the
program during scan, for that case the programmer defines such
addresses after the program is assembled.
b) Two pass assembler
• This type of assembler scans the assembly language twice.
• First pass generates symbol table of names and labels used in the
program and calculates their relative address.
• This table can be seen at the end of the list file and here user need
not define anything.
• Second pass uses the table constructed in first pass and completes
the object code creation.
• This assembler is more efficient and easier than earlier.
2) Linking:
• This involves the converting of .OBJ module into .EXE(executable) module
i.e. executable machine code.
• It completes the address left by the assembler.
• It combines separately assembled object files.
• Linking creates .EXE, .LIB, .MAP files among which last two are optional
files.
3) Loading and Executing:
• It Loads the program in memory for execution.
• It resolves remaining address.
• This process creates the program segment prefix (PSP) before loading.
• It executes to generate the result.
• Sample program assembling object Program linking executable program
Addressing modes in 8086:
;program to add ten numbers
TITLE Program to add ten numbers .MODEL SMALL
.STACK 64
.DATA
ARR DB 73, 91, 12, 15, 79, 94, 55, 89 SUM DW ?
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
MOV CX, 10
MOV AX, 0
LEA BX, ARR
L2: ADD Al, [BX]
JNC L1
INC AH
L1: INC BX
LOOP L2
MOV SUM, AX
MOV AX, 4C00H
INT 21H
MAIN ENDP
END MAIN
DOS FUNCTIONS AND INTERRUPTS (KEYBOARD
AND VIDEO PROCESSING)