0% found this document useful (0 votes)
53 views70 pages

Chapter 03 8086

The document discusses the 8086 microprocessor. It has a 16-bit architecture and can address up to 1MB of memory. It is divided into a Bus Interface Unit (BIU) and Execution Unit (EU). The BIU fetches instructions and handles data transfer, while the EU decodes and executes instructions. The 8086 has 16-bit registers like AX, BX, CX and DX and uses segments and offsets to generate physical addresses. It also has status and control flags. Assembly language is used to program the 8086 using mnemonics that map to machine instructions.

Uploaded by

hari kc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views70 pages

Chapter 03 8086

The document discusses the 8086 microprocessor. It has a 16-bit architecture and can address up to 1MB of memory. It is divided into a Bus Interface Unit (BIU) and Execution Unit (EU). The BIU fetches instructions and handles data transfer, while the EU decodes and executes instructions. The 8086 has 16-bit registers like AX, BX, CX and DX and uses segments and offsets to generate physical addresses. It also has status and control flags. Assembly language is used to program the 8086 using mnemonics that map to machine instructions.

Uploaded by

hari kc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

Chapter 03:

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)

• The CS contains the base or start of the current code segment.


• The IP contains the distance or offset from this address to the next
instruction byte to be fetched.
• Code segment address plus an offset value in the IP indicates the
address of an instruction to be fetched for execution.
• Data Segment
Data segment Contains the starting address of a program’s data
segment. Instructions use this address to locate data. This address
plus an offset value in an instruction, causes a reference to a specific
byte location in the data segment.
• Stack segment (SS) and Stack Pointer (SP)
Stack segment Contains the starting address of a program’s stack
segment. This segment address plus an offset value in the stack
pointer indicates the current word in the stack being addressed.
• Extra Segment(ES)
It is used by some string (character data) to handle memory
addressing. The string instructions always use the ES and destination
index (DI) to determine 20 bit physical address.
Execution Unit (EU)

• The EU decodes and executes the instrucHons.


• The EU contains arithmeHc and logic (ALU), a control unit, and a
number of registers.
• These features provide for execuHon of instrucHons and arithmeHc
and logical operaHons.
• It has nine 16 bit registers which are AX, BX, CX, DX, SP, BP, SI, DI and
flag. First four can be used as 8 bit register (AH, Al, BH, BL, CH, DH,
DL)
• AX Register
AX register is called 16 bit accumulator and AL is called 8 bit accumulator.
The I/O (IN or OUT) instrucAons always use the AX or AL for
inpuFng/OutpuFng 16 or 8 bit data from or to I/O port.
• BX Register
BX is known as the base register since it is the only general purpose register
that can be used as an index to extend addressing. The BX register is similar
to the 8085’s H, L register. BX can also be combined with DI or SI as C base
register for special addressing.
• CX register:
The CX register is known as the counter register because some instrucAons
such as SHIFT, ROTATE and LOOP use the contents of CX as a Counter.
• DX register:
The DX register is known as data register. Some I/O operaAons require its
use and mulAply and divide operaAons that involve large values assume
the use of DX and AX together as a pair. DX comprises the rightmost 16 bits
of the 32-bit EDX.
• Stack Pointer (SP) and Base Pointer (BP):
Both are used to access data in the stack segment. The SP is used as
an offset from the current stack segment during execution of
instructions. The SP’s contents are automatically updated
(increment/decrement) during execution of a POP and PUSH
instructions.
The BP contains the offset address in the current stack segment. This
offset is used by instructions utilizing the based addressing mode.
• Index register:
The two index registers SI (Source index) and DI (Destination Index)
are used in indexed addressing. The instructions that process data
strings use the SI and DI index register together with DS and ES
respectively, in order to distinguish between the source and
destination address.
Flags
• Flag register:
The 8086 has nine 1 bit flags. Out of 9 six are status and three are
control flags.
• The control bits in the flag register can be set or reset by the
programmer.
• O- Overflow flag This flag is set if an arithmetic overflow occurs, i.e. if the result of a signed
operation is large enough to be accommodated in a destination register.
• D-Direction Flag This is used by string manipulation instructions. If this flag bit is ‘0’ , the string is
processed beginning from the lowest address to the higher address, i.e. auto incrementing mode
otherwise the string is processed from the highest address towards the lowest address, i.e.
autodecrementing mode.
• I-Interrupt flag If this flag is set the maskable interrupts are recognized by the CPU, otherwise
they are ignored.
• T- Trap flag If this flag is set the processor enters the single step execution mode. In other words,
a trap interrupt is generated after execution of each instruction. The processor executes the
current instruction and the control is transferred to the Trap interrupt service routine.
• S - Sign flag: This flag is set when the result of any computation is negative. For signed
computations, the sign flag equals the MSB of the result.
• Z- Zero This flag is set when the result of the computation is or comparison performed by the
previous instruction is zero. 1 for zero result, 0 fir nonzero result
• A- Auxiliary Carry This is set if there is a carry from the lowest nibble, i.e. bit three during the
addition or borrow for the lowest nibble i.e. bit three, during subtraction.
• P- Parity flag This flag is set to 1 if the lower byte of the result contains even number of 1s
otherwise reset.
• C-Carry flag This flag is set when there is a carry out of MSB in case of addition or a borrow in
case of subtraction.
SEGMENT AND OFFSET ADDRESS:
• Segments are special areas defined in a program for containing the code,
data and stack. A segment begins on a paragraph boundary. A segment
register is of 16 bits in size and contains the starting address of a segment.
• A segment begins on a paragraph boundary, which is an address divisible
by decimal 16 or hex 10. Consider a DS that begins at location 038EOH. In
all cases, the rightmost hex digit is zero, the computer designers decided
that it would be unnecessary to store the zero the zero digit in the segment
register. Thus 038E0H is stores in register as 038EH.
• The distance in bytes from the segment address to another location within
the segment is expressed as an offset or displacement. Suppose the offset
of 0032H for above example of data segment. Processor combines the
address of the data segment with the offset as:
• SA: OA (segment address: offset address) 038E: 0032 H = 038E * 10 +0032
= 038EO + 0032 Physical address = 03912H
Pin diagram of 8086
8086 instrucJons
3) Data Transfer Instructions
4) Program execution transfer instructions
5) Processor control flag instructions
6) String instructions
8086 Assembly language programming
• 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
• To make programming easier, many programmers write programs in
assembly language
• They then translate Assembly Language program to machine language
so that it can be loaded into memory and run.
ADVANTAGES OF ASSEMBLY LANGUAGE

• A Program wriRen in Assembly Language requires considerably less Memory


and execuTon Tme 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 RouTne (that handles I/P and O/P) are almost always
developed in Assembly Language.
• Provides more control over handling parTcular H/W requirements.
• Generates smaller and compact executable modules.
• Results in faster execuTon.
TYPICAL FORMAT OF AN ASSEMBLY LANGUAGE INSTRUCTION

LABEL OPCODE FIELD OPERAND COMMENTS FIELD


NEXT: ADD AL,07H ; Add correcTon factor
• Assembly language statements are usually wriUen in a standard form that has 4 fields.
• A label is a symbol used to represent an address. They are followed by colon .
• Labels are only inserted when they are needed so it is an opTonal field.
• The opcode field of the instrucTon contains the mnemonics for the
• instrucTon to be performed
• The instrucTon mnemonics are someTmes called as operaTon codes.
• The operand field of the statement contains the data, the memory address, the
port address or the name of the register on which the instrucTon 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.
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
• An Assembler Program is used to translate the assembly language mnemonics for instruction to the corresponding binary codes.
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.
• It usually converts .exe file to .bin file.
• A Locator program EXE2BIN converts .exe file to .bin file.
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.
• It allows to set the breakpoint.
6. EMULATOR
• An Emulator is a mixture of hardware and software.
• It is used to test and debug the hardware and software of an external system such as the prototype of a Microprocessor based
system.
ASSEMBLY LANGUAGE PROGRAM FEATURES
#PROGRAM COMMENTS
• The use of Comments throughout a program can improve its clarity, especially in Assembly Language.
• A Comment begins with Semicolon. EXAMPLE
• MOV AX, BX ; Adds the Content of BX with AX
#RESERVED WORDS
• Instructions
• Directives
• Operators
• Predefined Symbols
#IDENTIFIERS
• : MOV , ADD
: END,SEGMENT : FAR,OFFSET
: @DATA
• 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.
• NAME : Refers to the Address of a data item COUNTER DB 0
• LABEL: Refer to the Address of an instruction, procedure, or segment. 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.
ASSEMBLY LANGUAGE PROGRAMMING USING MASM GENERAL
PATTERN FOR WRITING ALP IN MASM
[PAGE DIRECTIVE]
[TITLE DIRECTIVE]
[MEMORY MODEL DEFINITION] [SEGMENT DIRECTIVES] [PROC
DIRECTIVES]
...................................................
...................................................
...................................................
...................................................
[END DIRECTIVES]
BASIC FORMAT OF ALP BASED UPON THE GENERAL PATTERN
PAGE 60,80
TITLE "ALP TO PRINT FACTORIAL NO"
.MODEL [MODEL NAME] .STACK
.DATA
........................... ; INITIALIZE DATA VARIALBLES .CODE
MAIN PROC
................................
................................ ; INSTRUCTION SETS

.................................
................................
.................................
................................
.................................
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

• As already menToned, the ENDP DirecTve indicates the end of a procedure.


• An END DirecTve ends the enTre Program and appears as the last statement.
• Its Format is
END [PROCEDURE NAME]
THE EQU DIRECTIVE

• It is used for redefining symbolic names


• EXAMPLE:

DATAX DB 25
DATA EQU DATAX
DEFINING TYPES OF DATA

• The Format of Data Definition is given as [NAME] DN [EXPRESSION]


• EXAMPLES
STRING DB 'HELLO WORLD' NUM1 DB 10
NUM2 DB 90
1. CHARACTER STRINGS
• Character Strings are used for descriptive data.
• Consequently DB is the conventional format for defining character
data of any length
• An Example is
DB 'Computer City'
DB "Hello World"

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)

• The Intel CPU recognizes two types of interrupts namely hardware


interrupt when a peripheral devices needs attention from the CPU
and software interrupt that is call to a subroutine located in the
operating system.
• The common software interrupts used here are INT 10H for video
services and INT 21H for DOS services.
INT 21H:
• It is called the DOS function call for keyboard operations follow the
function number. The service functions are listed below:
# 00H- It terminates the current program.
- Generally not used, function 4CH is used instead.
# 01H- Read a character with echo
- Wait for a character if buffer is empty
- Character read is returned in AL in ASCII value
# 02H- Display single character
- Sends the characters in DL to display
- MOV AH, 02H
- MOV DL, ‘A’ ; move Dl, 65
- INT 21H
# 03H and 04H Auxiliary input/output
- INT 14H is preferred.
# 05H Printer service
- Sends the character in DL to printer
# 06H- Direct keyboard and display
- Displays the character in DL.
# 07H- waits for a character from standard input
- does not echo
# 08H- keyboard input without echo
- Same as function 01H but not echoed.
# 09H- string display
- Displays string until ‘$’ is reached.
- DX should have the address of the string to be displayed.
# 0AH Read string
# OBH- Check keyboard status
• Returns FF in AL if input character is available in keyboard buffer.
• Returns 00 if not.
• # 0CH- Clear keyboard buffer and invoke input functions such as 01,
06, 07, 08 or 0A.
• AL will contain the input function.
End of Chapter 03

You might also like