Microprocessors & Interfacing For GITAM University ECE
Microprocessors & Interfacing For GITAM University ECE
Course Objectives:
1. To study the architecture of the general purpose microprocessors
8085 and 8086.
2. To understand the assembly language programming of both 8085
and 8086 processors.
3. To impart knowledge about assembly language programming to
interface various peripherals like data converters, keyboards,
display units etc.,
4. To interface different peripheral units with microprocessors i.e., the
hardware of various consumer electronic goods.
5. To design and implement microprocessor based embedded
systems.
Course Outcomes:
Students will be able to
1. Acquire the knowledge of the internal architecture, memory
organization and operating modes of processors.
2. To write efficient codes on 8 bit and 16-bit platform.
3. interface the microprocessor with different peripheral ICs such as
8255, 8251, 8257, 8279 etc.,
4. Design standalone microprocessor - based systems.
Prepared by
Dr Sreenivasa Rao Ijjada
Dept of ECE,GIT, GITAM University, Visakhapatnam
2019-2020
[email protected]
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 1
Module I: 8085 Microprocessors & Architecture
4-Bit Microprocessors
8-Bit Microprocessors
16-Bit Microprocessors
32-Bit Microprocessors
64-Bit Microprocessors
1. History:
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 2
IV
Dual Core 64-bit 2006
Core 2 2006
Core i7 2008
Core i5 2009
Core i3 2010
Motorola
6800 8-bit 64KB 40 1974
6809 8-bit 64KB 40 1978
68000 16-bit 16MB 64 1979
68020 32-bit 4GB 169 PGA 200000 1984
68030 32-bit 4GB 169 PGA
68040 32-bit 4GB
Zilog
z-80 8-bit 64KB 40
z-800 8-bit 500K
z-8000 16-bit 64KB
It is a 2nd generation microprocessor and is the base for studying and using all
the microprocessor available in the market.
It is an 8 bit microprocessor.
It has 16(A0-A15) bit address lines (AB), hence can address up to 216 =
65536 (64K) memory locations.
Six 8-bit general purpose register arranged in pairs: BC, DE, HL.
System Bus
Bus is a group of conducting wires which carries information, all the peripherals
are connected to microprocessor through Bus. There are three different types of
buses.
Address bus
Data Bus
Control Bus
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 3
Address bus –It is a group of conducting wires which carries address only. AB is
unidirectional because address flows in one direction, from μp to memory or from
μp to Input/output devices. The range of Address of 8085 μp is from 0000 H to
FFFF H. The μp can address 65, 536 different memory location. The Length of the
AB determines the amount of memory can be handled. Actual amount of memory
can be accessed is usually much less than this theoretical limit due to chipset
and motherboard limitations.
Data bus –It is a group of conducting wires which carries Data only. DB is
bidirectional because data flow in both directions, from μp to memory or
Input/Output devices and from memory or Input/Output devices to μp. It is
ranging from 00 H to FF H. In write operation, the μp will put the data on the DB,
where as in read operation, the memory controller will get the data from specific
memory block and put it into the DB.
The width of the DB is directly related to the largest number that the bus can
carry, such as an 8 bit bus can represent 2 to the power of 8 unique values, this
equates to the number 0 to 255. A 16 bit bus can carry 0 to 65535.
Control bus –It is a group of conducting wires, which is used to generate timing
and control signals to control all the associated peripherals, μp uses control bus
to process data, that is what to do with selected memory location. Some control
signals are:
Memory read
Memory write
I/O read
I/O Write
Opcode fetch
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 4
If one line of control bus may be the read/write line. Low on this line indicates
the read operation, if this is high, it is write operation.
ALE (Address Latch Enable) signal: It goes high during first T state of a every
machine cycle and enables the lower 8-bits of the address, and for the rest of the
T states of the machine cycles the lower 8-bits are data nines.
IO/M’ – It is a status signal which determines whether the address is for input-
output or memory. When it is high (1) the address on the address bus is for
input-output devices. When it is low(0) the address on the address bus is for the
memory.
RD’ – It is a signal to control READ operation. When it is low the selected memory
or input-output device is read.
WR’ – It is a signal to control WRITE operation. When it goes low the data on the
data bus is written into the selected memory or I/O location.
SO, S1 – These are status signals. They distinguish the various types of
operations such as halt, reading, instruction fetching or writing.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 5
Architecture:
The 8085 has 6 general-purpose registers to store 8-bit data; these are identified
as- B, C, D, E, H, and L. They can be combined as register pairs – BC, DE, and
HL, to perform 16-bit operations. These registers are used to store or copy
temporary data during the execution of the program.
Accumulator: The accumulator is an 8-bit register (can store 8-bit data) that is
the part of the arithmetic and logical unit (ALU). After performing arithmetical or
logical operations, the result is stored in accumulator. Accumulator is also
defined as register A.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 6
Fig 1.3: flag register
Sign Flag: It is 7thbit of the flag register, which is also known as the MSB. It
helps the programmer to know whether the number in the accumulator is
positive or negative. After any operation if the MSB of the result is 1, it in
indicates the number is negative and the sign flag becomes set, i.e. 1. If the
MSB is 0, it indicates the number is positive and the sign flag becomes reseti.e.0.
from 00H to 7F, sign flag is 0 from 80H to FF, sign flag is 11- MSB is 1 (negative)
0- MSB is 0 (positive)
Example:
Zero Flag: 6th bit of the flag register. After any arithmetical or logical operation if
the result is 0 (00)H, the zero flag becomes set i.e. 1, otherwise it becomes
reset i.e. 0.00H zero flag is 1.from 01H to FFH zero flag is 01- zero result, 0-
non-zero result. It helps in determining if two numbers are equal or not.
Example:
MVI A, 10 //A=10H
SUB A //(A = A – A)
Auxiliary Carry Flag (AC): It is 4th bit of the flag register. This flag is used in
BCD number system (0-9). If after any arithmetic or logical operation B(3)
generates any carry and passes on to B(4) this flag becomes set i.e. 1, otherwise it
becomes reset i.e. 0. Note –Flag register in 8085 which is not accessible by user
Example:
MOV A, 2B //A=2BH
MOV B ,39 //B=39H
ADD B //(A = A + B)
A= , AC=11
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 7
Parity Flag: It is 2nd bit of the flag register. This flag tests for number of 1’s in the
accumulator. If after any arithmetic or logical operation the result has even
parity, if the accumulator holds even number of 1’s, it is set, P=1. On the
other hand if the number of 1’s is odd, then it is reset, P=0, it is said to be odd
parity.
Carry Flag: 0th bit of the flag register. Carry is generated when performing n bit
operations and the result is more than n bits, then this flag becomes set i.e. 1,
otherwise it becomes reset i.e. 0. During subtraction (A-B), if A>B it becomes
reset and if (A<B) it becomes set. Carry flag is also called borrow flag.1-carry out
from MSB bit on addition or borrow into MSB bit on subtraction 0-no carry out
or borrow into MSB bit
Example:
MVI A 30 //A=30H
MVI B 40 //B=40H
SUB B // (A = A – B)
since A<B,CY=1 as 30 – 40 generates a carry/borrow.
MVI A 40 //A=40H
MVI B 30 //B=30H
SUB B //(A = A – B)
since A>B,CY=0 as 40 – 30 generates a carry/borrow.
(c) Memory Registers –There are two 16-bit registers used to hold memory
addresses. The size of these registers is 16 bits because the memory addresses
are 16 bits. They are:-
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 8
5 Reset signals 2
6 DMA signals 2
7 Serial I/O signals 2
1. Address Bus & Data Bus: The AB is a group of sixteen lines i.e A0-A15. The
AB is unidirectional, i.e., bits flow in one direction from the microprocessor unit
to the peripheral devices and uses the high order address bus.
ALE – Address Latch Enable signal. It goes high during first T state of a machine
cycle and enables the lower 8-bits of the address, if its value is 1 otherwise data
bus is activated.
IO/M’ – It is a status signal which determines whether the address is for input-
output or memory. When it is high(1) the address on the address bus is for input-
output devices. When it is low(0) the address on the address bus is for the
memory.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 9
IO/M’ S1 S0 Operation
0 0 0 HALT
0 0 1 Memory WRITE
0 1 0 Memory READ
0 1 1 OPCODE FETCH
1 0 1 I/O Read
1 1 0 I/O Read
1 1 1 interrupt ack
RD’( To control READ operation): When it is low the selected memory or input-
output device is read.
WR’( To control WRITE operation): When it goes low the data on the data bus is
written into the selected memory or I/O location.
XI, X2(CLK in) – A crystal is connected at these two pins. The frequency is
internally divided by two, therefore, to operate a system at 3MHZ the crystal
should have frequency of 6MHZ.
CLK OUT – This signal can be used as the system clock for other devices.
The 8085 has five interrupt signals that can be used to interrupt a program
execution.
(i)INTR (ii)RST 7.5 (iii) RST 6.5 (iv) RST 5.5 (v) TRAP
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 10
In addition to Interrupts, there are three externally initiated signals namely
RESET, HOLD and READY. To respond to HOLD request, it has one signal called
HLDA.
5. Reset Signals:
RESET IN’ – When the signal on this pin is low(0), the program-counter is set
to zero, the buses are tristated and the microprocessor unit is reset.
RESET OUT – This signal indicates that the MPU is being reset. The signal can
be used to reset other devices.
6. DMA Signals:
HOLD – It indicates that another device is requesting the use of the address
and data bus. Having received HOLD request the microprocessor relinquishes
the use of the buses as soon as the current machine cycle is completed.
Internal processing may continue. After the removal of the HOLD signal the
processor regains the bus.
HLDA – It is a signal which indicates that the hold request has been received
after the removal of a HOLD request, the HLDA goes low.
Serial transmission in 8085 is implemented by the two signals SID and SOD
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 11
Instruction set:
Opcode
Operand
T state: A portion of an operation carried out in one system clock period is called as
T-state
Instruction set of 8085 is classified based on size and based on the operation
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 12
Single byte instructions
Two byte instructions
Three byte instructions
1Byte instruction: these instructions requires only one memory location for the storing
in the memory.
Ex: MOV,ADD,SUB,ORA,ANA.INR,DCR
2 Byte instruction: these instructions requires two one memory location for the storing
in the memory.
Ex: All the instructions with ending letter ‘I’, except LXI
3 Byte instruction: these instructions requires only three memory location for the
storing in the memory.
Arithmetic instructions--20
Logical instructions--19
Branch transfer instructions--8
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 13
Branching(8)
JUMP conditional/unconditional
CALL conditional/unconditional
RET conditional/unconditional
PCHL
RST-N
• JC • CC • RC • RST 0
• JNC • CNC • RNC • RST 1
• JP • CP • RP • RST 2
• JM • CM • RM • RST 3
• JPE • CPE • RPE • RST 4
• JPO • CPO • RPO • RST 5
• JZ • CZ • RZ • RST 6
• JNZ • CNZ • RNZ • RST 7
Data transfer instructions: They copy the data from a register (i/o or memory)
called source to another register (memory or i/o) called the destination.
Destination and the source registers are any of the 7 general purpose registers.
Memory to memory transfer is not available. Data transfer instructions will not
modify any flag after execution of the instructions.
MVI R, 8Bit data: this instruction directly copies the 8 bit data which is available
in the instruction itself in to the specified register.
MVI B,42H
2B-2M/C-7T
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 14
Opcode fetch -4T
Memory read-3T
A=47H=0100 0111
B=51H=0101 0001
------------------------- S Z - AC - P - CY
A=98H=1001 1000 1 0 X 0 X 0 X 0
A=76H=0111 0110
S Z - AC - P - CY
((HL))=A2H=1010 0010 0 0 X 0 X 1 X 1
-----------------------------
ACI 57H
A=26H=0010 0110
S Z - AC - P - CY
57H=0101 0111 0 0 X 0 X 1 X 0
------------------------
A=7E=0111 1110
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 15
MOV A,B // A=24H
ADC D // A=CY+A+D=1+24+54=79H
MOV H,A //H=79H
S Z - AC - P - CY
0 0 X 0 X 0 X 0
CY=1,A=26H
ACI 57H
A=26H=0010 0110 S Z - AC - P - CY
57H=0101 0111 0 0 X 0 X 1 X 0
CY=1= 1
-------------------------
A=7EH=0111 1110
-----------------------
SUB C
A=37H,C=40H,
A=37H=0011 0111------0011 0111 S Z - AC - P - CY
-C=40H=0100 0000-----1100 0000 1 0 X 0 X 0 X 0
------------------------- ----------------
F7H 1111 0111=-9
A=40H
SUI 37H
S Z - AC - P - CY
A=40H=0100 0000-------0100 0000 0 0 X 0 X 1 X 1
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 16
Ex: B=25H
INR B S Z - AC - P - CY
0 0 X 0 X 0 X 0
B=25H=0010 0101
+1H=0000 0001
-------------------------
B=26H=0010 0110
Ex: HL=3000H
3000H 71H
71H=0111 0001
+1H=0000 0001
---------------------- S Z - AC - P - CY
0 0 X 0 X 1 X 0
((HL))=A1H=0111 0010
INX Rp: (Increment register pair by 1): The specified register pair content is
incremented by one and is stored in the same place. No flags are modified.
INX Rp 1B-1M/C-6T Opcode fetch -6T
BC=9FFFH
INX B
BC=9FFFFH=1001 1111 1111 1111
+1=0000 0000 0000 0001
-------------------------------------------------
BC=A000H= 1010 0000 0000 0000
DCR R/M (Decrement register/Memory by 1): The specified register or memory
content is decremented by one and is stored in the same place. No flags are
modified. All the flags are modified except carry flag.
DCR R 1B-1M/C-4T Opcode fetch -4T
DCR M 1B-3M/C-10T Opcode fetch -4T
Memory read-3T
Memory Write-3T
Ex: B=00H
DCR B
B=00H=0000 0000 S Z - AC - P - CY
1 0 X 0 X 1 X 0
-1H=1111 1111
-------------------------
B=FFH=1111 1111
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 17
Ex: HL=3000H
DCX Rp(Decrement register pair by 1): the specified register pair content is
decremented by one and is stored in the same place. no flags are modified.
DCX Rp 1B-1M/C-6T Opcode fetch -6T
Ex: DE=1FFFH
DCX D
DE=1FFFFH=0001 1111 1111 1111
-1=1111 1111 1111 1111
-------------------------------------------------
DE=1FFEH=1 0001 1111 1111 1110
DAD Rp: (Add register pair to HL) 16 bit addition: this instruction is used to
add the content of HL with the content of the register pair specified in the
instruction. If the result is greater than 16 bits, then the carry flag is set and no
other flags are modified. This instruction also used to multiply the HL content by
2.
LOGICAL INSTRUCTIONS
µP is basically a programmable logic chip, hence it can perform all logical
functions through its instructions such as Rotate, AND,OR,EX-OR and NOT. All
the logic operations are performed in the accumulator.
1 AND 3 ANA,R
ANA,M
ANI,8 bit data
2 OR 3 ORA,R
ORA,M
ORI,8bit data
3 EX OR 3 XRA,R
XRA,M
XRI,8bit data
4 Rotate 4 RAR
RRC
RAL
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 19
RLC
5 NOT 3 STC
CMC
CMA
6 Compare 3 CMP,R
CMP,M
CPI,8 bit data
Addressing modes:
• To perform any operation, we have to give the corresponding instructions to
the microprocessor.
• In each instruction, programmer has to specify 3 things:
– Operation to be performed.
– Address of source of data.
– Address of destination of result.
The method by which the address of source of data or the address of destination
of result is given in the instruction is called Addressing Modes. The term
addressing mode refers to the way in which the operand of the instruction is
specified.
Types of addressing modes:
i) Immediate Addressing Mode
ii)Register Addressing Mode
iii) Direct Addressing Mode
iv) Register Indirect Addressing Mode
v)Implicit Addressing Mode
i)Immediate Addressing Mode: In immediate addressing mode the source
operand is always data. If the data is 8-bit, then the instruction will be of 2 bytes,
if the data is of 16-bit then the instruction will be of 3 bytes.
Examples:
MVI B, 45 //B=45H
LXI H 3050 // HL=3050H
JMP address //jump to the operand address immediately
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 20
ADD B // A=A+B
INR A // A=A+1
iii)Direct Addressing Mode: In direct addressing mode, the data to be operated
is available inside a memory location and that memory location is directly
specified as an operand. The operand is directly available in the instruction itself.
Examples:
LDA 2050 // (A)=(2050)
LHLD address //(HL)=(contents of 16-bit memory location)
IN 35 //(read the data from port whose address is 35)
iv)Register Indirect Addressing Mode: In register indirect addressing mode, the
data to be operated is available inside a memory location and that memory
location is indirectly specified b a register pair.
Examples:
MOV A, M //(A)=((HL))
LDAX B //(A)=(BC)
LXIH 9570 //(HL)=9570
v)Implied/Implicit Addressing Mode: In implied/implicit addressing mode the
operand is hidden and the data to be operated is available in the instruction
itself.
Examples:
CMA //(A)=1’s complement of the accumulator A)
RRC //(rotate accumulator A right by one bit)
RLC //(rotate accumulator A left by one bit)
Interrupt structure:
When the microprocessor receives any interrupt signal from peripheral(s) which
are requesting its services, it stops its current program execution and program
control is transferred to a sub-routine by generating a CALL signal and after
executing sub-routine by generating RET signal again the program control is
transferred to the main program from where it had stopped.
Mainly in the microprocessor based system the interrupts are used for data
transfer between the peripheral and the microprocessor.
Interrupts can be classified into various categories based on different parameters:
i) Internally generate interrupts & externally generated interrupts
ii) Hardware & Software interrupts
iii) Maskable & non Maskable interrupts
iv) Vector and non vector interrupts
Internally generated interrupts: Interrupts arises due to the use of illegal
instructions or using of erroneous data. These are synchronous signals
Ex: register overflow, divide by zero, using of invalid operation
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 21
Externally generated interrupts: If the request is coming through hardware
pins they are called externally generated interrupts. These are asynchronous
signals
Ex: power supply failure, timing device signals
Hardware and Software Interrupts: When microprocessors receive interrupt
signals through pins (hardware) of microprocessor, they are known
as Hardware Interrupts. There are 5 Hardware Interrupts.
They are – INTR, RST 7.5, RST 6.5, RST 5.5, TRAP
Software Interrupts are those which are inserted in between the program which
means these are nemonics of microprocessor. There are 8 software interrupts.
They are – RST 0, RST 1, RST 2, RST 3, RST 4, RST 5, RST 6, RST 7.
Non-Vectored Interrupts: the interrupts whose vector address is not yet
predefined. The interrupting device gives the address of sub-routine for these
interrupts.
Ex: INTR
Non-Vectored Interrupt address generation:
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 22
Vectored Interrupts: Which have fixed vector address (starting address of sub-
routine) and after executing these, program control is transferred to that address.
Vector Addresses are calculated by the formula 8 * TYPE
Interrupt Decimal address Vector address
RST-0 0 0000H
RST-1 8 0008H
RST-2 16 0010H
RST-3 24 0018H
RST-4 32 0020H
TRAP 34 0024H
RST-5 40 0028H
RST-5.5 44 002CH
RST-6 48 0030H
RST-6.5 52 0034H
RST-7 56 0038H
RST-7.5 60 003CH
Maskable Interrupts: The interrupts which can be disabled or ignored by the
microprocessor. These interrupts are either edge-triggered or level-triggered, so
they can be disabled. Ex:INTR, RST 7.5, RST 6.5, RST 5.5
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 23
Non-Maskable Interrupts: The interrupts which cannot be disabled or ignored by
microprocessor. TRAP is a non-maskable interrupt. It consists of both level
as well as e dge triggering and is used in critical power failure conditions.
Enable Interrupt (EI) – The interrupt enable flip-flop is set and all interrupts are
enabled following the execution of next instruction followed by EI. No flags are
affected. After a system reset, the interrupt enable flip-flop is reset, thus disabling
the interrupts. This instruction is necessary to enable the interrupts again
(except TRAP).
Disable Interrupt (DI) – This instruction is used to reset the value of enable flip-
flop hence disabling all the interrupts. No flags are affected by this instruction.
Set Interrupt Mask (SIM) – It is used to implement the hardware interrupts (RST
7.5, RST 6.5, RST 5.5) by setting various bits to form masks or generate output
data via the Serial Output Data (SOD) line. First the required value is loaded in
accumulator then SIM will take the bit pattern from it.
RIM: This instruction is used to read the status of the hardware interrupts (RST
7.5, RST 6.5, RST 5.5) by loading into the A register a byte which defines the
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 24
condition of the mask bits for the interrupts. It also reads the condition of SID
(Serial Input Data) bit on the microprocessor.
Interrupt priority
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 25
Module I the Processor 8086
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 26
8086 features: 8086 is a 16-bit Integer processor packed in DIP (Dual Inline
Packaged) IC in a 40 pin. 8086 has 14 internal registers, each of 16 bits or 2
Bytes wide. The size of the internal registers indicate how much information the
processor can operate on at a time and how it moves data around internally
within the chip, sometimes also referred to as the internal data bus.
8086 has four 16 bit general purpose registers AX, BX, CX and DX. Store
intermediate values during execution. Each of these has two 8 bit parts (higher
and lower).
It provides the interface of 8086 to external memory and I/O devices via the
System Bus. It performs memory read, I/O read etc. to transfer the data between
memory and I/O devices.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 27
It generates the 20 bit physical address for memory access.
It fetches instructions from the memory.
It transfers data to and from the memory and I/O.
Maintains the 6 byte pre-fetch instruction queue (supports pipelining).
BIU mainly contains the 4 Segment registers, the Instruction Pointer, a pre-
fetch queue and an Address Generation Circuit.
Example:
CS = 4321H IP = 1000H
Then CS x 10H = 43210H + offset = 53210H
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 28
addressing stack segment of memory. The stack segment is that segment of
memory, which is used to store stack data.
Functions of EU
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 29
Register organization:
Special purpose registers (16-bit): The pointers contain within the particular
segments. The pointers IP, BP, SP usually contain offsets within the code, data
and stack segments respectively
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 30
Stack Pointer: It is a 16-bit register to pointing to program stack in the
stack segment, which always Points the top of the stack. It is used during
the instructions like PUSH, POP, CALL, RET etc.
Base Pointer: It is a 16-bit register pointing the data in stack segment. BP
can hold offset address of any location in the stack segment. It is used to
access random locations of the stack. BP register is used for based, based
indexed or register indirect addressing.
Source Index: It is a 16-bit register. It holds offset address in Data
Segment during string operations.SI is used for indexed, based indexed and
register indirect addressing, as well as a source data addresses in string
manipulation instructions.
Destination Index: It is a 16-bit register and is used for indexed, holds
offset address in Extra Segment during string operations. It is used in
based indexed and register indirect addressing, as well as a destination
data addresses in string manipulation instructions.
The EU fetches an opcode from the queue into the instruction register. The
instruction decoder decodes it and sends the information to the control circuit for
execution.
Flag/Status register: It is 16 bit register as shown in the fig., only 9 flags are
defined to change or recognize the state of the microprocessor.
Status flags: Status flags are updated after every arithmetic and logic operation.
1. carry flag(CF)
2. parity flag(PF)
3. auxiliary carry flag(AF)
4. zero flag(Z)
5. sign flag(S)
6. Overflow flag(OV)
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 31
Carry Flag (CY): This flag indicates an overflow condition for unsigned integer
arithmetic. It is also used in multiple-precision arithmetic.
Parity Flag (PF): This flag is used to indicate the parity of result. If lower order
8-bits of the result contains even number of 1’s, the Parity Flag is set and for odd
number of 1’s, the Parity flag is reset.
Zero Flag (ZF): It is set; if the result of arithmetic or logical operation is zero else
it is reset.
Sign Flag (SF): In sign magnitude format the sign of number is indicated by MSB
bit. If the result of operation is negative, sign flag is set.
Control flags: The Control flags are used to control certain operations. Control
flags are set or reset deliberately to control the operations of the execution unit.
Control flags are as follows:
o trap flag(TF)
o interrupt flag(IF)
o direction flag(DF)
These flags can be set or reset using control instructions like CLC, STC, CLD,
STD, CLI, STI, etc.
Trap Flag (TF): It is used for single step control. It allows user to execute one
instruction of a program at a time for debugging. When trap flag is set, program
can be run in single step mode.
Direction Flag (DF): It is used in string operation. If it is set, string bytes are
accessed from higher memory address to lower memory address. When it is reset,
the string bytes are accessed from lower memory address to higher memory
address.
Arithmetic Logic Unit (16 bit): Performs 8 and 16 bit arithmetic and logic
operations.
PIN Diagram:
The pin diagram of 8086 is shown in the fig. Intel 8086 is a 16-bit HMOS
microprocessor. It is available in 40 pin DIP chip. It uses a 5V DC supply for its
operation. The 8086 uses 20-line address bus. It has a 16-line data bus. The 20
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 32
lines of the address bus operate in multiplexed mode. The 16-low order address
bus lines have been multiplexed with data and 4 high-order address bus lines have
been multiplexed with status signals.
Pins 16-39: It is a multiplexed low order Address/Data bus (AD0-AD15). These are
address bus. When AD lines are used to transmit memory address the symbol A is used
instead of AD, for example A0-A15. When data are transmitted over AD lines the symbol
D is used in place of AD, for example D0-D7, D8-D15 or D0-D15.
Pins 35-38(A16/S3, A17/S4, A18/S5, A19/S6): High order address bus multiplexed
with status signals.
Pin 32(RD’): This is used for read operation. It is an output signal. It is active
when low.
Pin 29( LOCK’) : It is an active low pin. It indicates that other system bus
masters have not been allowed to gain control of the system bus while LOCK’ is
active low (0). The LOCK signal will be active until the completion of the next
instruction.
Pins 26-28(S2, S1, S0): Status pins. These pins are active during T4, T1 and T2
states and is returned to passive state (1,1,1 during T3 or Tw (when ready is
inactive). These are used by the 8288 bus controller for generating all the memory
and I/O operation) access control signals. Any change in S2, S1, S0 during T4
indicates the beginning of a bus cycle.
S2 S1 S0 Characteristics
0 0 0 Interrupt acknowledge
0 0 1 Read I/O port
0 1 0 Write I/O port
0 1 1 Halt
1 0 0 Code access
1 0 1 Read memory
1 1 0 Write memory
1 1 1 Passive state
Pins 24-25(QS1,QS0) : Queue Status. These signals indicate the status of the
internal 8086 instruction queue according to the table shown below
Queue Status
Qs1 Qs0 Q status
0 0 Queue is ideal
0 1 1st byte of the opcode
1 0 Queue is empty
1 1 Subsequent byte of queue
Pin 23( TEST’) : This examined by a ‘WAIT’ instruction. If the TEST pin goes
low(0), execution will continue, else the processor remains in an idle state. The
input is internally synchronized during each of the clock cycle on leading edge of
the clock.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 34
Pin 22(READY) : This is the acknowledgement from the memory or slow device
that they have completed the data transfer. The signal made available by the
devices is synchronized by the 8284A clock generator to provide ready input to
the microprocessor. The signal is active high(1).
Pin 21(RESET): This pin requires the microprocessor to terminate its present
activity immediately. The signal must be active high (1) for at least four clock
cycles.
Pin 19( CLK) : Clock Input. The clock input provides the basic timing for
processing operation and bus control activity. Its an asymmetric square wave
with a 33% duty cycle.
Pin 18(INTR): Interrupt Request. This is triggered input. This is sampled during
the last clock cycles of each instruction for determining the availability of the
request. If any interrupt request is found pending, the processor enters the
interrupt acknowledge cycle. This can be internally masked after resulting the
interrupt enable flag. This signal is active high(1) and has been synchronized
internally.
Pin 17(NMI): Non maskable interrupt. This is an edge triggered input which
results in a type II interrupt. A subroutine is then vectored through an interrupt
vector lookup table which is located in the system memory. NMI is non-maskable
internally by software. A transition made from low(0) to high(1) initiates the
interrupt at the end of the current instruction. This input has been synchronized
internally.
Pin 40 (Vcc): 8086 microprocessor requires +5.0 V D.C with a supply voltage tolerance of
±10%. The 8086 uses a maximum supply current of 360 mA. Operate in ambient
temperatures of between 32° F and 180° F. 80C86 is CMOS version that requires only 10
mA of power supply current and function in temperature extremes of -40°F through
+225° F.
Minimum mode pins (24-31): Minimum mode operation of the 8086 is obtained by
connecting the MN/ MX’ pin directly to +5.0 V. Do not connect this pin to +5.0 V through
a pull-up register, or it will not function correctly.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 35
Pin 26(DEN): Data enable. This pin is provided as an output enable for the
8286/8287 in a minimum system which uses transceiver. DEN is active low(0)
during each memory and input-output access and for INTA cycles.
Pin 28(M/IO’): The M/IO’ pin selects memory or I/O. This pin indicates that the
microprocessor address bus contains either a memory address or an I/O port
address. This pin is at its high-impedance state during a hold acknowledge.
Pin 29(WR’): The write line is a strobe that indicates that the 8086 is outputting
data to a memory or I/O device. During the time that WR’ the is a logic 0, the
data bus contains valid data for memory or I/O. This pin floats to a high
impedance during a hold acknowledge.
Code segment register (CS): is used for addressing memory location in the
code segment of the memory, where the executable program is stored.
Data segment register (DS): points to the data segment of the memory
where the data is stored.
Extra Segment Register (ES): also refers to a segment in the memory
which is another data segment in the memory.
Stack Segment Register (SS): is used for addressing stack segment of the
memory. The stack segment is that segment of memory which is used to
store stack data.
The number of address lines in 8086 is 20, 8086 BIU will send 20bit address, so
as to access one of the 1MB memory locations. The four segment registers
actually contain the upper 16 bits of the starting addresses of the four memory
segments of 64 KB each with which the 8086 is working at that instant of time. A
segment is a logical unit of memory that may be up to 64 kilobytes long. Each
segment is made up of contiguous memory locations. It is an independent,
separately addressable unit. Starting address will always be changing. It will not
be fixed.
Note that the 8086 does not work the whole 1MB memory at any given time.
However, it works only with four 64KB segments within the whole 1MB memory.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 36
Below is the one way of positioning four 64KB segments within the 1M byte
memory space of an 8086.
Types of Segmentation –
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 37
Advantages of the Segmentation The main advantages of segmentation
are as follows:
Physical Memory organization: 8086μP has 20 bit address bus hence it can
address up to 220≈ 1M memory space (00000H-FFFFFH). This is divided in to two
independent banks of 512 KB size each as shown in the fig. Data bytes associated
with an even address (00000, 00002..., FFFFE) reside in the low bank (even
bank). Data bytes associated with an odd addresses (00001, 00003, ....., FFFFF)
reside in the high bank (odd bank). Address bits A1 through A19 are connected to
both the banks to select the accessed memory location. BLE’ (Bus low enable) A0
& BHE’ (Bus high enable) signals are used as bank-select signals for lower and
upper banks respectively. 8086μP has 16 data line to carry the data even though
each memory location holds only 1byte of data. Hence, the even bank transfers
data bytes over D0 -D7 data lines, while the odd bank uses D8-D15 for transfer the
data.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 38
To read/write a byte data, 1M/C is sufficient whereas for a word data transfer, it
may take either 1or 2 bus cycles depending on the starting address of the word.
This is illustrated in table below.
Case 1: To read/write a byte from /into a memory location in the even bank with
the starting address is 00000H. BHE’&A0=10, will select the even bank and
deactivates the odd bank, and a byte will be transferred through D0 -D7 data
lines.
Case 2: To read/write a byte from /into a memory location in the odd bank with
the starting address is 00001H. BHE’&A0=01, will select the odd bank and
disable the even bank, and a byte will be transferred through D8 –D15 data lines.
Case 3: To read/write a word from/into the memory with the starting address is
00000(even). Since A0=0, even bank has selected, and μP will generate BHE’=0,
hence high lower bank also selected. As both the banks have individual data line,
with in 1st bus cycle a word can be transferred.
Case 4: To read/write a word from/into the memory with the starting address is
00001(odd). Initially A0=1 hence even bank is disabled, at the same time μP will
grant BHE’=0 signal, hence the odd bank is enabled for the 1st M/C and a byte
will be transferred through D8 –D15 data lines. During the 2nd M/C, μP will send
the address as 00002H, hence A0=0, and processor will generate BHE’ signal as
high, hence even bank selected, now the byte data transfer will be done through
D0 –D7.
Timing Diagram:
Fig shows that the signal activities on the 8086 µP buses during read and write
operations.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 39
Fig. Timing diagram of 8086
During 1st T state of every M/C, the ALE is high to enable the address latches.
After the address passed through latches, 8086 will bring the ALE to low again to
latch the address on the O/Ps of the latches. After the address has latched, µP
removes the address information from AD0-AD15 and outputs desired data on
the data bus. Then it asserts the WR’=0.
If the system is large enough to need buffers on the DB, then DT/R’ will be
connected to the direction input on the buffers. During a write cycle, 8086 will
assert DT/R’ high to put the buffers in the transmit mode. When 8086 asserts
DEN’ low to enable the buffers, data O/P from 86 will pass through buffers to the
addressed port or memory.
Write M/C: During 1st T state, the signal M/IO’ is Low if the write address is
port or High if the write address is memory. Then 8086 outputs BHE’ and the
address, that it will be writing to on AD0-AD19. When the writing is IO port then
A16-A19 will be low.
Read cycle: ALE makes a transition from low to high during 1st T state of every
machine cycle and then goes from high to low. With the trailing edge of the ALE
the address information is latched at the o/p of the latch and holds throughout
the machine cycle. M/IO’ and DT/R’ settle down accordingly at the beginning of
M/C and remains as it is throughout the M/C. In read M/C, during T2 the RD’
and DEN’ signals makes transition from high to low and is continued throughout
the M/C. During the T3, the µP just waits and in T4 it will draws RD’ and DEN’
signals and whatever the data in the data bus takes it is valid data.
Write cycle: ALE makes a transition from low to high during 1st T state of every
machine cycle and then goes from high to low. With the trailing edge of the ALE
the address information is latched at the o/p of the latch and holds throughout
the machine cycle. M/IO’ signal will settle down and DT/R’ makes a transition
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 41
from low to high accordingly at the beginning of the M/C and unchanged
throughout the M/C. In write M/C, during T2 the WR’ and DEN’ make transition
from high to low as they are active low signals. During the T3 µP just waits and
in T4 it will draws WR’ and DEN’ signals and whatever the data in the data bus
takes it is valid data.
If ready pin is low somewhere before end of T2 then at the end of T2 it will be
sampled by the processor and after T3 instead of generating T4 state, the
processor generate one wait state. During the wait state the status of AB, DB and
CBs remains unchanged and the READY pin is sampled by the processor. If it is
still low one more wait state is introduced. This process will be continued until
the READY pin is high. Once the READY pin is high the processor will generate
the T4 T state and ends the machine cycle.
Maximum mode of operation: This mode selects with MN/MX’ pin=0. Maximum
mode is used only when the system contains external coprocessors such as 8087
arithmetic coprocessor and 8089 I/O coprocessor. In this mode, the host
processor and the coprocessors will share the common property of system bus.
Both 8087/8089 has their own instruction set and capable of performing complex
arithmetic operations upon floating point data as well as several I/O operations.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 42
Fig.2.9: Maximum mode of operation
The program for 8086 and instructions of 8087/8089 can stay together in the
main memory. When it executed by a single processor in ALP, the 8087
instruction is recognized as if the first letter is F. 8086 fetches the whole program
and bytes containing op-codes, addressing mode, address/data reaches the
instruction queue inside the processor. The same type also reaches the queue of
8087. If the particular instruction is for 8086, then 8087 will treat that
instruction as NOP for him and vice versa. Max. mode of operation differs from
the Min. mode in the way some of the control signals must be generated
externally.
The pins 24-31 will have the functions described by the mnemonics next to the
pins. In max mode, 8288 (external bus controller to provide the signals eliminated
from the 8086 by the maximum mode operation, as there are not enough for bus
control during maximum mode) is required to translate the control signals for
system which has two or more µPs sharing the same bus. This additional
circuitry converts the status signals (S2’-S0’) into the I/O and memory transfer
signals as shown in the table. Also generates the control signals required to direct
the data flow and for controlling 8282 octal latches are used to demultiplex the
address signals and 8286 bidirectional transceivers are used to buffer the data
bus so that it can drive a boardful of devices as shown in fig.
Table
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 43
Read cycle: Maximum mode is a multiprocessor mode, where the status signals
S2’-S0’ shows which system is activated and which system is deactivated. These
status signal will be active for the first 2 T states and deactivated 2 T states and
again
Write cycle: ALE is high for 1st T state, the status signals S2’-S0’ shows which
system is activated and which system is deactivated. These status signal will be
active for the first 2 T states and deactivated 2 T states and again. DT/R’ is high
for data transfer. During 1st T state, the signal M/IO’ is Low if the write address
is port or High if the write address is memory. Then 8086 outputs BHE’ and the
address, that it will be writing to on AD0-AD19. When the writing is IO port then
A16-A19 will be low.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 44
8288 bus controller: Fig illustrates the block diagram and pin-out of the 8288
bus controller. The control bus developed by the 8288 bus controller contains
separate signals for I/O (IORC’ and IOWC’) and memory ( MRDC’ and MWTC’).
Also contains advanced memory (AMWC) and I/O (AIOWC’) write strobes, and
INTA’ signal. These signals replace the minimum mode ALE,WR’,IO/M’,
DT/R’,DEN’, and INTA’, which are lost when the 8086 microprocessors are
operated in the maximum mode.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 45
S2-S0 Status inputs are connected to the status output pins on the
8086 microprocessor. These three signals are decoded to
generate the timing signals for the system
CLK The clock input provides internal timing and must be
connected to the CLK output pin of the 8284A clock
generator.
ALE The address latch enable output is used to demultiplex the
address/data bus
DEN The data bus enable pin controls the bidirectional data bus
buffers in the system. This is an active high output pin that
is the opposite polarity from the DEN’ signal found on the
microprocessor when operated in the minimum mode.
DT/R’ The data transmit/receive signal is output by the 8288 to
control the direction of the bidirectional data bus buffers.
AIOWC’/AMWC’ Advance I/O Write Command/Advance Memory
Write Command. These signals are similar to IOWC
and MWTC except that they are activated one clock
pulse earlier. This gives slow interfaces an extra clock
cycle to prepare to input the data.
AEN’ IOB CEN The control enable input enables the command output pins
on the 8288.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 46
Module 3: Instruction set and Programming
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 47
8086 INSTRUCTION SET
Data Transfer Instructions: These instructions are used to transfer the data from
the source operand to the destination operand. Following are the list of
instructions under this group −
MOV − Used to copy the byte or word from the provided source to the
provided destination.
PPUSH − Used to put a word at the top of the stack.
POP − Used to get a word from the top of the stack to the provided location.
PUSHA − Used to put all the registers into the stack.
POPA − Used to get words from the stack to all registers.
XCHG − Used to exchange the data from two locations.
XLAT − Used to translate a byte in AL using a table in the memory.
IN − Used to read a byte or word from the provided port to the accumulator.
OUT − Used to send out a byte or word from the accumulator to the
provided port.
LEA − Used to load the address of operand into the provided register.
LDS − Used to load DS register and other provided register from the
memory
LES − Used to load ES register and other provided register from the
memory.
LAHF − Used to load AH with the low byte of the flag register.
SAHF − Used to store AH register to low byte of the flag register.
PUSHF − Used to copy the flag register at the top of the stack.
POPF − Used to copy a word at the top of the stack to the flag register.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 48
Arithmetic Instructions: These instructions are used to perform arithmetic
operations like addition, subtraction, multiplication, division, etc.
DIV − Used to divide the unsigned word by byte or unsigned double word
by word.
IDIV − Used to divide the signed word by byte or signed double word by
word.
AAD − Used to adjust ASCII codes after division.
CBW − Used to fill the upper byte of the word with the copies of sign bit of
the lower byte.
CWD − Used to fill the upper word of the double word with the sign bit of
the lower word.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 49
Instructions to perform shift operations
SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in
LSBs.
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in
MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old
MSB into the new MSB.
ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB
and to Carry Flag [CF].
ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB
and to Carry Flag [CF].
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF
and CF to MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and
CF to LSB.
CALL − Used to call a procedure and save their return address to the stack.
RET − Used to return from the procedure to the main program.
JMP − Used to jump to the provided address to proceed to the next
instruction.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 50
JA/JNBE − Used to jump if above/not below/equal instruction satisfies.
JAE/JNB − Used to jump if above/not below instruction satisfies.
JBE/JNA − Used to jump if below/equal/ not above instruction satisfies.
JC − Used to jump if carry flag CF = 1
JE/JZ − Used to jump if equal/zero flag ZF = 1
JG/JNLE − Used to jump if greater/not less than/equal instruction
satisfies.
JGE/JNL − Used to jump if greater than/equal/not less than instruction
satisfies.
JL/JNGE − Used to jump if less than/not greater than/equal instruction
satisfies.
JLE/JNG − Used to jump if less than/equal/if not greater than instruction
satisfies.
JNC − Used to jump if no carry flag (CF = 0)
JNE/JNZ − Used to jump if not equal/zero flag ZF = 0
JNO − Used to jump if no overflow flag OF = 0
JNP/JPO − Used to jump if not parity/parity odd PF = 0
JNS − Used to jump if not sign SF = 0
JO − Used to jump if overflow flag OF = 1
JP/JPE − Used to jump if parity/parity even PF = 1
JS − Used to jump if sign flag SF = 1
Iteration Control Instructions: These instructions are used to execute the given
instructions for number of times.
Interrupt Instructions: These instructions are used to call the interrupt during
program execution.
INT − Used to interrupt the program during execution and calling service
specified.
INTO − Used to interrupt the program during execution if OF = 1
IRET − Used to return from interrupt service to the main program
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 51
DATA TRANSFER INSTRUCTIONS
MOV – MOV Destination, Source
LEA – LEA Register, Source: Determines the offset of the variable or memory
location named as the source and puts this offset in the indicated 16-bit register.
LEA does not affect any flag.
LDS – LDS Register, Memory address of the first word: Loads new values into
the specified register and into the DS register from four successive memory
locations. The word from two memory locations is copied into the specified
register and the word from the next two memory locations is copied into the DS
registers. LDS does not affect any flag.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 52
LDS SI, SPTR Copy content of memory at displacement SPTR and SPTR + 1in
DS to SI register. Copy content of memory at displacements
SPTR + 2 and SPTR + 3 in DS to DS register. DS: SI now
points at start of the desired string.
LES – LES Register, Memory address of the first word: Loads new values into
the specified register and into the ES register from four successive memory
locations. The word from the first two memory locations is copied into the
specified register, and the word from the next two memory locations is copied into
the ES register. LES does not affect any flag.
ARITHMETIC INSTRUCTIONS
ADD AL, 74H //Add immediate number 74H to content of AL. Result in AL
ADC CL, BL //Add content of BL plus carry status to content of CL
ADD DX, BX //Add content of BX to content of DX
ADD DX, [SI] //Add word from memory at offset [SI] in DS to content of DX
ADC AL, PRICES [BX] //Add byte from effective address PRICES [BX] plus
carry status to content of AL
ADD AL, PRICES [BX] //Add content of memory at EA address PRICES [BX]
to AL
SUB – SUB Destination, Source
To multiply a byte with a word, first move the byte to a word location such as
an extended register and fill the upper byte of the word with all 0’s. Cannot use
the CBW instruction for this, because the CBW instruction fills the upper byte
with copies of the most significant bit of the lower byte
IMUL – IMUL Source: Multiplies a signed byte/word from a source with a signed
byte/word in AL/AX. Source can be a register/a memory location. When a byte
from source is multiplied with content of AL, the signed result will be in AX.
When a source word is multiplied by AX, the result will be in DX and AX.
If the magnitude of the product does not require all the bits of the destination, the
unused byte / word will be filled with copies of the sign bit. If the upper byte of a
16-bit result or the upper word of a 32-bit result contains only copies of the sign
bit (all 0’s or all 1’s), then CF=OF=0; If it contains a part of the product,
CF=OF=1. AF, PF, SF and ZF are undefined after IMUL.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 54
To multiply a signed byte with a signed word, first move the byte into a word
location and fill the upper byte of the word with copies of the sign bit. If move
the byte into AL, use the CBW instruction.
To divide a byte by a byte, first put the dividend byte in AL and fill AH with all
0’s. Likewise, to divide a word by another word, then put the dividend word in
AX and fill DX with all 0’s.
IDIV – IDIV Source: Used to divide a signed word by a signed byte, or to divide a
signed double word by a signed word. When dividing a signed word by a signed
byte, the word must be in AX register.
The divisor can be in an 8-bit register/ a memory location. After the division, AL
will contain the signed quotient, and AH will contain the signed remainder. The
sign of the remainder will be the same as the sign of the dividend. If an attempt is
made to divide by 0, the quotient is greater than 127 (7FH) or less than –127
(81H), the 8086 will automatically generate a type 0 interrupt.
When dividing a signed double word by a signed word, the most significant
word of the dividend (numerator) must be in the DX register, and the least
significant word of the dividend must be in the AX register. The divisor can be
in any other 16-bit register or memory location. After the division, AX will
contain a signed 16-bit quotient, and DX will contain a signed 16-bit
remainder. The sign of the remainder will be the same as the sign of the
dividend. Again, if an attempt is made to divide by 0, the quotient is greater
than +32,767 (7FFFH) or less than –32,767 (8001H), the 8086 will
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 55
automatically generate a type 0 interrupt. All flags are undefined after an IDIV.
To divide a signed byte by a signed byte, first put the dividend byte in AL and
sign-extend AL into AH. The CBW instruction can be used for this purpose. To
divide a signed word by a signed word, put the dividend word in AX and extend
the sign of AX to all the bits of DX. The CWD instruction can be used for this
purpose.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 56
DAA (DECIMAL ADJUST AFTER BCD ADDITION): Used to make sure the result
of adding two packed BCD numbers is adjusted to be a legal BCD number. The
result of the addition must be in AL for DAA to work correctly. If the lower nibble
in AL after an addition is greater than 9 or AF was set by the addition, then the
DAA instruction will add 6 to the lower nibble in AL. If the result in the upper
nibble of AL in now greater than 9 or if the carry flag was set by the addition or
correction, then the DAA instruction will add 60H to AL.
DAS (DECIMAL ADJUST AFTER BCD SUBTRACTION): Used after subtracting one
packed BCD number from another packed BCD number, to make sure the result
is correct packed BCD. The result of the subtraction must be in AL for DAS to
work correctly. If the lower nibble in AL after a subtraction is greater than 9 or
the AF was set by the subtraction, then the DAS instruction will subtract 6 from
the lower nibble AL. If the result in the upper nibble is now greater than 9 or if
the carry flag was set, the DAS instruction will subtract 60 from AL.
CBW (CONVERT SIGNED BYTE TO SIGNED WORD): Copies the sign bit of the
byte in AL to all the bits in AH. AH is then said to be the sign extension of AL.
CBW does not affect any flag.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 57
AAA (ASCII ADJUST FOR ADDITION): Numerical data coming into a computer
from a terminal is usually in ASCII code. In this code, the numbers 0 to 9 are
represented by the ASCII codes 30H to 39H. The 8086 allows to add the ASCII
codes for two decimal digits without masking off the “3” in the upper nibble of
each. After the addition, the AAA instruction is used to make sure the result is
the correct unpacked BCD.
The AAA instruction works only on the AL register. The AAA instruction
updates AF and CF; but OF, PF, SF and ZF are left undefined.
The AAS instruction works only on the AL register. It updates ZF and CF; but
OF, PF, SF, AF are left undefined.
AAM (BCD ADJUST AFTER MULTIPLY): Before you can multiply two ASCII
digits, you must first mask the upper 4 bit of each. This leaves unpacked BCD
(one BCD digit per byte) in each byte. After the two unpacked BCD digits are
multiplied, the AAM instruction is used to adjust the product to two unpacked
BCD digits in AX. AAM works only after the multiplication of two unpacked BCD
bytes, and it works only the operand in AL. AAM updates PF, SF and ZF but AF;
CF and OF are left undefined.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 58
AAD (BCD-TO-BINARY CONVERT BEFORE DIVISION)
AAD converts two unpacked BCD digits in AH and AL to the equivalent binary
number in AL. This adjustment must be made before dividing the two
unpacked BCD digits in AX by an unpacked BCD byte. After the BCD division,
AL will contain the unpacked BCD quotient and AH will contain the unpacked
BCD remainder. AAD updates PF, SF and ZF; AF, CF and OF are left
undefined.
LOGICAL INSTRUCTIONS
AND – AND Destination, Source: This instruction ANDs each bit in a source
byte or word with the same numbered bit in a destination byte or word. The
result is put in the specified destination. The content of the specified source is
not changed.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 59
XOR – XOR Destination, Source: This instruction Exclusive-ORs each bit in a
source byte or word with the same numbered bit in a destination byte or word.
The result is put in the specified destination. The content of the specified source
is not changed.
NOT – NOT Destination: The NOT instruction inverts each bit (forms the 1’s
complement) of a byte or word in the specified destination. The destination can be
a register or a memory location. This instruction does not affect any flag.
CMP – CMP Destination, Source: This instruction compares a byte / word in the
specified source with a byte / word in the specified destination. The source can
be an immediate number, a register, or a memory location. The destination can
be a register or a memory location. However, the source and the destination
cannot both be memory locations. The comparison is actually done by
subtracting the source byte or word from the destination byte or word. The source
and the destination are not changed, but the flags are set to indicate the results
of the comparison. AF, OF, SF, ZF, PF, and CF are updated by the CMP
instruction. For the instruction CMP CX, BX, the values of CF, ZF, and SF will be
as follows:
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 60
CF Z S
F F
CX = BX 0 1 0 Result of subtraction is 0
CX > BX 0 0 0 No borrow required, so CF =
0
CX < BX 1 0 1 Subtraction requires borrow,
so CF = 1
TEST – TEST Destination, Source: This instruction ANDs the byte / word in the
specified source with the byte / word in the specified destination. Flags are
updated, but neither operand is changed. The test instruction is often used to set
flags before a Conditional jump instruction.
RCL – RCL Destination, Count: This instruction rotates all the bits in a
specified word/byte by some number of bit positions to the left. The operation
circular because the MSB of the operand is rotated into the carry flag and the bit
in the carry flag is rotated around into LSB of the operand. For multi-bit rotates,
CF will contain the bit most recently rotated out of the MSB.
CF MSB LSB
RCL affects only CF and OF. OF will be a 1 after a single bit RCL if the MSB
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 61
was changed by the rotate. OF is undefined after the multi-bit rotate.
RCR – RCR Destination, Count: This instruction rotates all the bits in a
specified word/byte by some number of bit positions to the right. The operation
circular because the LSB of the operand is rotated into the carry flag and the bit
in the carry flag is rotate around into MSB of the operand. For multi-bit rotate,
CF will contain the bit most recently rotated out of the LSB.
CF MSB LSB
RCR affects only CF and OF. OF will be a 1 after a single bit RCR if the MSB
was changed by the rotate. OF is undefined after the multi-bit rotate.
ROL – ROL Destination, Count: This instruction rotates all the bits in a
specified word/byte to the left some number of bit positions. The data bit rotated
out of MSB is circled back into the LSB. It is also copied into CF. In the case of
multiple-bit rotate, CF will contain a copy of the bit most recently moved out of
the MSB. The destination can be a register/a memory location.
CF MSB LSB
To rotate the operand by one bit position, specify this by putting 1 in the count
position in the instruction. To rotate more than one bit position, load the
desired number into the CL register and put “CL” in the count position of the
instruction.
ROL affects only CF and OF. OF will be a 1 after a single bit ROL if the MSB was
changed by the rotate.
ROL AX, 1 //Rotate the word in AX 1 bit position left, MSB to LSB and CF
MOV CL, 04H //Load number of bits to rotate in CL ROL BL, CL Rotate BL 4
bit positions
ROL FACTOR [BX], 1 //Rotate the word or byte in DS at EA = FACTOR [BX]
by 1 bit position left into CF
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 62
ROR – ROR Destination, Count: This instruction rotates all the bits in a
specified word/byte some number of bit positions to right. The operation is
desired as a rotate rather than shift, because the bit moved out of the LSB is
rotated around into the MSB. The data bit moved out of the LSB is also copied
into CF. In the case of multiple bit rotates, CF will contain a copy of the bit most
recently moved out of the LSB.
CF MSB LSB
ROR BL, 1 //Rotate all bits in BL right 1 bit position LSB to MSB and to CF
MOV CL, 08H //Load CL with number of bit positions to be rotated ROR
WORD PTR [BX], CL //Rotate word in DS at offset [BX] 8 bit position right
SAL – SAL Destination, Count SHL – SHL Destination, Count: SAL and SHL
are two mnemonics for the same instruction. This instruction shifts each bit in
the specified destination some number of bit positions to the left. As a bit is
shifted out of the LSB operation, a 0 is put in the LSB position. The MSB will be
shifted into CF. In the case of multi-bit shift, CF will contain the bit most recently
shifted out from the MSB. Bits shifted into CF previously will be lost.
CF MSB LSB 0
The flags are affected as follow: CF contains the bit most recently shifted out
from MSB. For a count of one, OF will be 1 if CF and the current MSB are not
the same. For multiple-bit shifts, OF is undefined. SF and ZF will be updated to
reflect the condition of the destination. PF will have meaning only for an
operand in AL. AF is undefined.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 63
SAR – SAR Destination, Count: This instruction shifts each bit in the specified
destination some number of bit positions to the right. As a bit is shifted out of the
MSB position, a copy of the old MSB is put in the MSB position. In other words,
the sign bit is copied into the MSB. The LSB will be shifted into CF. In the case of
multiple-bit shift, CF will contain the bit most recently shifted out from the LSB.
Bits shifted into CF previously will be lost.
The flags are affected as follow: CF contains the bit most recently shifted in
from LSB. For a count of one, OF will be 1 if the two MSBs are not the same.
After a multi-bit SAR, OF will be 0. SF and ZF will be updated to show the
condition of the destination. PF will have meaning only for an 8- bit
destination. AF will be undefined after SAR.
SAR DX, 1 //Shift word in DI one bit position right, new MSB = old MSB
MOV CL, 02H //Load desired number of shifts in CL
SAR WORD PTR [BP], CL //Shift word at offset [BP] in stack segment right
by two bit positions, the two MSBs are now copies of original LSB
SHR – SHR Destination, Count: This instruction shifts each bit in the specified
destination some number of bit positions to the right. As a bit is shifted out of the
MSB position, a 0 is put in its place. The bit shifted out of the LSB position goes
to CF. In the case of multi-bit shifts, CF will contain the bit most recently shifted
out from the LSB. Bits shifted into CF previously will be lost.
0 MSB LSB CF
The flags are affected by SHR as follow: CF contains the bit most recently
shifted out from LSB. For a count of one, OF will be 1 if the two MSBs are not
both 0’s. For multiple-bit shifts, OF will be meaningless. SF and ZF will be
updated to show the condition of the destination. PF will have meaning only for
an 8-bit destination. AF is undefined.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 64
TRANSFER-OF-CONTROL INSTRUCTIONS
Note:
The terms above and below are used when referring to the magnitude of
unsigned numbers. Ex: the number 00000111 (7) is above the number
00000010 (2), whereas the number 00000100 (4) is below the number
00001110 (14).
The terms greater and less are used to refer to the relationship of two signed
numbers. Greater means more positive. The number 00000111 (+7) is
greater than the number 11111110 (-2), whereas the number 11111100 (-4)
is less than the number 11110100 (-6).
In the case of Conditional jump instructions, the destination address must
be in the range of –128 bytes to +127 bytes from the address of the next
instruction
These instructions do not affect any flags.
This instruction will fetch the next instruction from the location specified in the
instruction rather than from the next location after the JMP instruction. Jump
is two ways
Near jump: If the destination is in the same code segment as the JMP
instruction, then only the instruction pointer will be changed to get the
destination location. This is referred to as a near jump. Near jump is again two
ways
Direct near jump
Indirect near jump
JMP BX: This instruction replaces the content of IP with the content of BX. BX
must first be loaded with the offset of the destination instruction in CS. This is
a near jump. It is also referred to as an indirect jump because the new value of
IP comes from a register rather than from the instruction itself, as in a direct
jump.
JMP WORD PTR [BX]: This instruction replaces IP with word from a memory
location pointed to by BX in DX. This is an indirect near jump.
Far Jump: If the destination for the jump instruction is in a segment with a
name different from that of the segment containing the JMP instruction, then
both the instruction pointer and the code segment register content will be
changed to get the destination location. This referred to as a far jump. The JMP
instruction does not affect any flag. Far jump is again two ways
JMP CONTINUE: This instruction fetches the next instruction from the
address at label CONTINUE. If the label is in the same segment, an offset coded
as part of the instruction will be added to the instruction pointer to produce
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 65
the new fetch address. If the label is another segment, then IP and CS will be
replaced with value coded in part of the instruction. This type of jump is
referred to as direct because the displacement of the destination or the
destination itself is specified directly in the instruction.
JAE / JNB / JNC (JUMP IF ABOVE OR EQUAL / JUMP IF NOT BELOW / JUMP
IF NO CARRY): If, after a compare or some other instructions which affect flags,
the CF=0, this instruction will cause execution to jump to a label given in the
instruction. If CF=1, the instruction will have no effect on program execution.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 66
JG / JNLE (JUMP IF GREATER / JUMP IF NOT LESS THAN OR EQUAL)
JGE / JNL (JUMP IF GREATER THAN OR EQUAL / JUMP IF NOT LESS THAN):
This instruction is usually used after a Compare instruction. The instruction will
cause a jump to the label given in the instruction, if the SF=OF.
JLE / JNG (JUMP IF LESS THAN OR EQUAL / JUMP IF NOT GREATER): This is
usually used after a CMP instruction. The instruction will cause a jump to the
label given in the instruction if the ZF=1 or if SF≠OF.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 67
JNE / JNZ (JUMP NOT EQUAL / JUMP IF NOT ZERO): This instruction is
usually used after a Compare instruction. If the zero flag is 0, then this
instruction will cause a jump to the label given in the instruction.
JNS (JUMP IF NOT SIGNED / JUMP IF POSITIVE): This instruction will cause a
jump to the specified destination address if the SF=0.
DEC AL //Decrement AL
JNS NEXT //Jump to label NEXT if AL has not decremented to FFH
JP / JPE (JUMP IF PARITY / JUMP IF PARITY EVEN): If the number of 1’s left in
the lower 8 bits of a data word after an instruction which affects the parity flag is
even, then the PF=1. If the parity flag is set, the JP / JPE instruction will cause a
jump to the specified destination address.
If the number of 1’s left in the lower 8 bits of a data word after an instruction
which affects the parity flag is odd, then the parity flag is 0. The JNP / JPO
instruction will cause a jump to the specified destination address, if the parity
flag is 0.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 68
JNO (JUMP IF NO OVERFLOW): The OF will be set if some signed arithmetic
operation is too large to fit in the destination register/memory location. The JNO
instruction will cause a jump to the destination given in the instruction, if the
overflow flag is not set.
JCXZ (JUMP IF THE CX REGISTER IS ZERO): This instruction will cause a jump
to the label to a given in the instruction, if the CX register contains all 0’s. The
instruction does not look at the zero flag when it decides whether to jump or not.
LOOPE / LOOPZ (LOOP WHILE CX ≠ 0 AND ZF = 1): This instruction is used to repeat
a group of instructions some number of times, or until the zero flag becomes 0.
The number of times the instruction sequence is to be repeated is loaded into CX.
Each time the LOOP instruction executes, CX is automatically decremented by 1.
If CX ≠ 0 and ZF = 1, execution will jump to a destination specified by a label in
the instruction. If CX = 0, execution simply go on the next instruction after
LOOPE / LOOPZ. In other words, the two ways to exit the loop are CX = 0 or ZF =
0. The destination address for the jump must be in the range of –128 bytes to
+127 bytes from the address of the instruction after the LOOPE / LOOPZ
instruction. This instruction does not affect any flag.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 69
LOOPE NEXT
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 70
CALL WORD PTR [BX]: This is an indirect within-segment (near or intra-
segment) call. Offset of the first instruction of the procedure is in two memory
addresses in DS. Replaces content of IP with content of word memory location
in DS pointed to by BX.
CALL DWORD PTR [BX]: This is an indirect call to another segment (far or
inter-segment call). New values for CS and IP are fetched from four-memory
location in DS. The new value for CS is fetched from [BX] and [BX + 1]; the new
IP is fetched from [BX + 2] and [BX +3].
The RET instruction will return execution from a procedure to the next
instruction after the CALL instruction which was used to call the procedure. If
the procedure is near procedure (in the same code segment as the CALL
instruction), then the return will be done by replacing the IP with a word from
the top of the stack. The word from the top of the stack is the offset of the next
instruction after the CALL. This offset was pushed into the stack as part of the
operation of the CALL instruction. The stack pointer will be incremented by 2
after the return address is popped off the stack.
If the procedure is a far procedure (in a code segment other than the one from
which it is called), then the instruction pointer will be replaced by the word at
the top of the stack. This word is the offset part of the return address put there
by the CALL instruction. The stack pointer will then be incremented by 2. The
CS register is then replaced with a word from the new top of the stack. This
word is the segment base part of the return address that was pushed onto the
stack by a far call operation. After this, the stack pointer is again incremented
by 2.
This instruction copies a byte or a word from location in the data segment to a
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 71
location in the extra segment. The offset of the source in the data segment
must be in the SI register. The offset of the destination in the extra segment
must be in the DI register. For multiple-byte or multiple-word moves, the
number of elements to be moved is put in the CX register so that it can
function as a counter. After the byte or a word is moved, SI and DI are
automatically adjusted to point to the next source element and the next
destination element. If DF is 0, then SI and DI will incremented by 1 after a
byte move and by 2 after a word move. If DF is 1, then SI and DI will be
decremented by 1 after a byte move and by 2 after a word move. MOVS does
not affect any flag.
When using the MOVS instruction, you must in some way tell the assembler
whether you want to move a string as bytes or as word. There are two ways to
do this. The first way is to indicate the name of the source and destination
strings in the instruction, as, for example. MOVS DEST, SRC. The assembler
will code the instruction for a byte / word move if they were declared with a DB
/ DW. The second way is to add a “B” or a “W” to the MOVS mnemonic.
MOVSB says move a string as bytes; MOVSW says move a string as words.
Note: The assembler uses the name of the string to determine whether the
string is of type bye or type word. Instead of using the string name to do this,
you can use the mnemonic LODSB to tell the assembler that the string is type
byte or the mnemonic LODSW to tell the assembler that the string is of type
word.
Note: The assembler uses the string name to determine whether the string is of
type byte or type word. If it is a byte string, then string byte is replaced with
content of AL. If it is a word string, then string word is replaced with content of
AX.
“B” added to STOSB mnemonic tells assembler to replace byte in string with
byte from AL. STOSW would tell assembler directly to replace a word in the
string with a word from AX.
CMPS / CMPSB / CMPSW (COMPARE STRING BYTES OR STRING WORDS)
This instruction can be used to compare a byte / word in one string with a byte
/ word in another string. SI is used to hold the offset of the byte or word in the
source string, and DI is used to hold the offset of the byte or word in the
destination string.
The AF, CF, OF, PF, SF, and ZF flags are affected by the comparison, but the
two operands are not affected. After the comparison, SI and DI will
automatically be incremented or decremented to point to the next or previous
element in the two strings. If DF is set, then SI and DI will automatically be
decremented by 1 for a byte string and by 2 for a word string. If DF is reset,
then SI and DI will automatically be incremented by 1 for byte strings and by 2
for word strings. The string pointed to by SI must be in the data segment. The
string pointed to by DI must be in the extra segment.
The CMPS instruction can be used with a REPE or REPNE prefix to compare all
the elements of a string.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 73
SCAS / SCASB / SCASW (SCAN A STRING BYTE OR A STRING WORD)
REP is a prefix, which is written before one of the string instructions. It will
cause the CX register to be decremented and the string instruction to be
repeated until CX = 0. The instruction REP MOVSB, for example, will continue
to copy string bytes until the number of bytes loaded into CX has been copied.
REPE and REPZ are two mnemonics for the same prefix. They stand for repeat
if equal and repeat if zero, respectively. They are often used with the Compare
String instruction or with the Scan String instruction. They will cause the
string instruction to be repeated as long as the compared bytes or words are
equal (ZF = 1) and CX is not yet counted down to zero. In other words, there
are two conditions that will stop the repetition: CX = 0 or string bytes or words
not equal.
REPE CMPSB Compare string bytes until end
of string or until string bytes
not equal.
REPNE and REPNZ are also two mnemonics for the same prefix. They stand for
repeat if not equal and repeat if not zero, respectively. They are often used with
the Compare String instruction or with the Scan String instruction. They will
cause the string instruction to be repeated as long as the compared bytes or
words are not equal (ZF = 0) and CX is not yet counted down to zero.
The string instruction used with the prefix determines which flags are affected.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 74
FLAG MANIPULATION INSTRUCTIONS
STC (SET CARRY FLAG): It sets the CF to 1. & does not affect any other flag.
CLC (CLEAR CARRY FLAG): It resets the CF to 0 & does not affect other flags.
CMC (COMPLEMENT CARRY FLAG): It complements the CF & does not affect any
other flag.
STD (SET DIRECTION FLAG): It sets the DF=1. It does not affect any other flag.
CLD (CLEAR DIRECTION FLAG): It resets the DF=0 & does not affect any other
flag.
STI (SET INTERRUPT FLAG): Setting IF=1 enables the INTR interrupt input of the
8086. When the INTR input is enabled, an interrupt signal on this input will
cause the interrupt program execution, push the return address and flags on the
stack, and execute an interrupt service procedure. An IRET instruction at the end
of the interrupt service procedure will restore the return address and flags that
were pushed onto the stack and return execution to the interrupted program. STI
does not affect any other flag.
CLI (CLEAR INTERRUPT FLAG): This instruction resets the IF=0. If the interrupt
flag is reset, the 8086 will not respond to an interrupt signal on its INTR input.
The CLI instructions, however, has no effect on the non-maskable interrupt
input, NMI. It does not affect any other flag.
The PUSH instruction decrements the stack pointer by 2 and copies a word
from a specified source to the location in the stack segment to which the stack
pointer points. The source of the word can be general- purpose register,
segment register, or memory. The stack segment register and the stack pointer
must be initialized before this instruction can be used. PUSH can be used to
save data on the stack so that it will not destroyed by a procedure. This
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 75
instruction does not affect any flag.
The POP instruction copies a word from the stack location pointed to by the
stack pointer to a destination specified in the instruction. The destination can
be a general-purpose register, a segment register or a memory location. The
data in the stack is not changed. After the word is copied to the specified
destination, the stack pointer is automatically incremented by 2 to point to the
next word on the stack. The POP instruction does not affect any flag.
The PUSHF instruction decrements the stack pointer by 2 and copies a word in
the flag register to two memory locations in stack pointed to by the stack
pointer. The stack segment register is not affected. This instruction does to
affect any flag.
The POPF instruction copies a word from two memory locations at the top of
the stack to the flag register and increments the stack pointer by 2. The stack
segment register and word on the stack are not affected. This instruction does
to affect any flag.
INPUT-OUTPUT INSTRUCTIONS
IN – IN Accumulator, Port
For the variable-port form of the IN instruction, the port address is loaded into
the DX register before the IN instruction. Since DX is a 16-bit register, the port
address can be any number between 0000H and FFFFH. Therefore, up to
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 76
65,536 ports are addressable in this mode.
The variable-port IN instruction has advantage that the port address can be
computed or dynamically determined in the program. Suppose, for example,
that an 8086-based computer needs to input data from 10 terminals, each
having its own port address. Instead of having a separate procedure to input
data from each port, you can write one generalized input procedure and simply
pass the address of the desired port to the procedure in DX.
OUT – OUT Port, Accumulator: The OUT instruction copies a byte from AL or a
word from AX to the specified port. The OUT instruction has two possible forms,
fixed port and variable port. For the fixed port form, the 8-bit port address is
specified directly in the instruction. With this form, any one of 256 possible ports
can be addressed.
For variable port form of the OUT instruction, the content of AL or AX will be
copied to the port at an address contained in DX. Therefore, the DX register
must be loaded with the desired port address before this form of the OUT
instruction is used.
MISCELLANEOUS INSTRUCTIONS
HLT (HALT PROCESSING): The HLT instruction causes the 8086 to stop fetching
and executing instructions. The 8086 will enter a halt state. The different ways to
get the processor out of the halt state are with an interrupt signal on the INTR
pin, an interrupt signal on the NMI pin, or a reset signal on the RESET input.
NOP (PERFORM NO OPERATION): This instruction simply uses upto three clock
cycles and increments the instruction pointer to point to the next instruction. The
NOP instruction can be used to increase the delay of a delay loop. When hand
coding, a NOP can also be used to hold a place in a program for an instruction
that will be added later. NOP does not affect any flag.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 77
ESC (ESCAPE): This instruction is used to pass instructions to a coprocessor,
such as the 8087 Math coprocessor, which shares the address and data bus with
8086. Instructions for the coprocessor are represented by a 6-bit code embedded
in the ESC instruction. As the 8086 fetches instruction bytes, the coprocessor
also fetches these bytes from the data bus and puts them in its queue. However,
the coprocessor treats all the normal 8086 instructions as NOPs. When 8086
fetches an ESC instruction, the coprocessor decodes the instruction and carries
out the action specified by the 6-bit code specified in the instruction. In most
cases, the 8086 treats the ESC instruction as a NOP. In some cases, the 8086 will
access a data item in memory for the coprocessor.
INT – INT TYPE: The term type in the instruction refers to a number between 0
and 255, which identify the interrupt. When an 8086 executes an INT instruction,
1. Decrement the SP by 2 and push the flags on to the stack.
2. Decrement the SP by 2 and push the content of CS onto the stack.
3. Decrement the SP by 2 and push the offset of the next instruction after the
INT number instruction on the stack.
4. Get a new IP value from an absolute memory address of 4*type number
specified in the instruction. For INT 8 instruction, the new IP will be read
from address 00020H.
5. Get a new CS value from an absolute memory address of 4* type specified
in the instruction+ 2, for INT 8 instruction, the new value of CS will be read
from address 00022H.
6. Reset both IF and TF. Other flags are not affected.
If the overflow flag (OF) is set, this instruction causes the 8086 to do an
indirect far call to a procedure you write to handle the overflow condition.
Before doing the call, the 8086 will
1. Decrement the SP by 2 and push the flags on to the stack.
2. Decrement the SP by 2 and push CS on to the stack.
3. Decrement the SP by 2 and push the offset of the next instruction after
INTO instruction onto the stack.
4. Reset TF and IF. Other flags are not affected.
5. To do the call, the 8086 will read a new IP value from address 00010H and
a new CS value from address 00012H.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 78
IRET (INTERRUPT RETURN): When the 8086 responds to an interrupt signal or
to an interrupt instruction, it pushes the flags, the current value of CS, and the
current value of IP onto the stack. It then loads CS and IP with the starting
address of the procedure, which you write for the response to that interrupt. The
IRET instruction is used at the end of the interrupt service procedure to return
execution to the interrupted program. To do this return, the 8086 copies the
saved value of IP from the stack to IP, the stored value of CS from the stack to
CS, and the stored value of the flags back to the flag register. Flags will have the
values they had before the interrupt, so any flag settings from the procedure will
be lost unless they are specifically saved in some way.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 79
XLAT / XLATB – TRANSLATE A BYTE IN AL: The XLATB instruction is used to
translate a byte from one code (8 bits or less) to another code (8 bits or less).
Instruction replaces a byte in AL register with a byte pointed to by BX in a lookup
table in the memory. Before the XLATB instruction can be executed, the lookup
table containing the values for a new code must be put in memory, and the offset
of the starting address of the lookup table must be loaded in BX. The code byte to
be translated is put in AL. The XLATB instruction adds the byte in AL to the
offset of the start of the table in BX. It then copies the byte from the address
pointed to by (BX + AL) back into AL. XLATB instruction does not affect any flag.
8086 routine to convert ASCII code byte to EBCDIC equivalent: ASCII code
byte is in AL at the start, EBCDIC code in AL after conversion.
MOV BX, OFFSET EBCDIC Point BX to the start of EBCDIC table in DS
XLATB Replace ASCII in AL with EBCDIC from table.
Dr.Sreenivasa Rao Ijjada, Dept of ECE, GIT, GITAM University Visakhapatnam Page 80
8086 ASSEMBLER DIRECTIVES
The assembler directives for Intel 8086 macro assembler (ASM86), Borland
Turbo assembler (TASM) and IBM macro assembler (MASM) are
ASSUME: used to tell the assembler the name of the logical segment it
should use for a specified segment.
Example ASSUME CS: CODE //tells the assembler that the instructions
for a program are in a logical segment named CODE.
ASSUME DS: DATA //tells the assembler that for any program
instruction, which refers to the data segment, should use the logical
segment called DATA.
ENDS (END SEGMENT): Used with the name of a segment to indicate the
end of that logical segment.
END (END PROCEDURE): The END directive is put after the last statement
of a program to tell the assembler that this is the end of the program
module. The assembler will ignore any statements after an END directive. A
carriage return is required after the END directive.
RESULT DT 20H DUP (0) //declare an array of 20H blocks of 10 bytes each
and initialize all 320 bytes to 00 when the program is loaded into memory to
be run.
Example: FACTOR EQU 03H //at the start of your program, and later in the
program writes the statement ADD AL, FACTOR. When the assembler codes
this instruction statement, it will code it as if you had written the
instruction ADD AL, 03H.
Ex MOV BX, OFFSET PRICES //it will determine the offset of the variable
PRICES from the start of the segment in which PRICES is defined and will
load this value into BX.
INC BYTE PTR [BX] //tells the assembler that to increment the byte pointed
to by BX.
INC WORD PTR [BX] //tells the assembler that we want to increment the
word pointed to by BX.
DATA SEGMENT
SALES DB 9 DUP (?) Location counter will point to 0009
after this instruction. EVEN Increment location counter to
000AH
INVENTORY DW 100 DUP (0) Array of 100 words starting on
even address for quicker read DATA ENDS
ENDP (END PROCEDURE): The directive is used along with the name of the
procedure to indicate the end of a procedure to the assembler. The directive,
together with the procedure directive, PROC, is used to “bracket” a
procedure.
NAME: The NAME directive is used to give a specific name to each assembly
module when programs consisting of several modules are written.
PROCEDURE SEGMENT
EXTRN DIVIDE: FAR //Found in segment PROCEDURES
PROCEDURE ENDS
SHORT: The SHORT operator is used to tell the assembler that only a 1 byte
displacement is needed to code a jump instruction in the program. The
destination must in the range of –128 bytes to +127 bytes from the address
of the instruction after the jump. The statement JMP SHORT
NEARBY_LABEL is an example of the use of SHORT.
Reg 00 01 10 11
Memory Memory mode with Memory mode with W=0 W-1
mode w/o 8 bit displacement 16 bit displacement
displacement
Every instruction of 8086 has one or more number of fields associated with
it. The first filled is called operation code field (opcode field), which indicates
the type of operation and the other fields are known as operand fields.
The source can be any one of eight 16 bit registers or a memory location
specified by any one of 24 addressing modes. Therefore there are total 32
different binary codes for specify the source. Similarly, to specify the
destination also there are 32 different binary codes.
Hence there are 64 different codes for MOV instruction where CX can be
used as either source or destination.
a) One byte Instruction: This format is one byte long only and may have
the implied data or register operands. The least significant 3 bits of
the opcode are used for specifying the register operand, if any.
Otherwise, all the eight bits form an opcode and the operands are
implied.
AAA = 00110111
b) Two byte Instruction: This format is 2 bytes long. The first byte of the
code specifies the operation code and the width of the operand specifies
by w bit. The second byte of the opcode shows the register operands
and RIM field.
Ex: Immediate operand to register: In this, the first byte and the 3
bits of the second byte (REG field) of register to register format are used
for opcode. It also contains one or two bytes of immediate data.
W=0; immediate data size is 8 bits and the size of instruction is 3 bytes.
Syllabus
NMI: Higher priority than INTR and is type 2 interrupt. When this interrupt
is activated, these actions take place
2. INT 1 (Single Step) - The processor executes this interrupt after every
instruction if the TF is set. It puts processor in single stepping mode
i.e. the processor pauses after executing every instruction. This is very
useful during debugging. Its ISR generally displays contents of all
registers. Its ISR address is stored at location 1 x 4 = 00004H in the
IVT.
3. INT 2 (Non mask-able Interrupt)- The processor executes this ISR in
response to an interrupt on the NMI line. Its ISR address is stored at
location 2 x 4 = 00008H in the IVT.
4. INT 3 (Breakpoint Interrupt)-It is a 1-byte instruction having op-code
is CCH. This interrupt is used to cause breakpoints in the program. It
is caused by writing the instruction INT 03H or simply INT. It is useful
in debugging large programs where single stepping is efficient. Its ISR
is used to display the contents of all registers on the screen. Its ISR
address is stored at location 3 x 4 = 0000CH in the IVT.
5. INT 4(INTO)- Interrupt on overflow instruction-It is a 1-byte
instruction and the op-code is CEH. This interrupt occurs if the
overflow flag is set. It is used to detect overflow error in signed
arithmetic operations. Its ISR address is stored at location 4 x 4 =
00010H in the IVT. If the overflow flag is reset then, the execution
continues to the next instruction.
C. Available interrupts (INT 32…..INT 225): There are 224 user defined
software interrupts. ISRs for these interrupts are written by the users
to service various user defined conditions. These interrupts are
invoked by writing the instruction INT n. Its ISR address is obtained
by the microprocessor from location n x 4 in the IVT.
IVT (Interrupt Vector table): Interrupt vectors are the addresses that inform
the interrupt handler as to where to find the ISR. All interrupts are assigned a
number from 0 to 255, with each of these interrupts being associated with a
specific interrupt vector. The 8086 series of µPs has an IVT situated at
0000:0000 which extends up to 1024 bytes. The IVT holds:
1. IVT is the link between an interrupt type code and the procedure to
service interrupts associated with that code. 8086 supports total 256
types i.e. 00H to FFH.
2. For each type it has to reserve four bytes i.e. double word. This double
word pointer contains the address of the procedure that is to service
interrupts of that type.
3. The higher addressed word of the pointer contains the base address of
the segment containing the procedure.
4. The lower addressed word contains the procedure’s offset from the
beginning of the segment.
5. Thus NEW CS: NEW IP provides NEW physical address from where
user ISR routine will start.
6. Since for each type, four bytes are required; the interrupt pointer table
occupies up to the first 1k bytes (i.e. 256 x 4 = 1024 bytes) of memory.
7. The total interrupt vector table is divided into three groups namely,
The starting address for type 0 interrupt is 000000H, for type1 interrupt is
00004H similarly for type2 is 00008H and ……so on. The interrupts from
Type 5 to Type 31 are reserved for other advanced microprocessors, and
interrupts from 32 to Type 255 are available for user defined interrupts.
Interrupt priority:
interrupt priority
Divide error, INT n, INT 0 highest
NMI
INTR
Single Step Lowest
Intel 8259A is one of the most common interrupt controller used in IBM
PCs. It can handle eight vectored priority interrupts for the CPU. It is a 28
pin DIP package and requires a single +5V DC supply for its operation. It is
designed to minimize the software and real time overhead in handling multi-
level priority interrupts. The 8259A is upward compatible with 8259. The
main difference between the two is that the 8259A can be used with Intel
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 100
8086/8088 processor. It also includes additional features such as level
triggered mode, buffered mode and automatic end of interrupt mode.
The pin diagram and internal block diagram of PIC is shown in figure. The
pins are defined as follows:
CS’ (Chip Select signal): To access the chip, CS’ signal must be made low, a
LOW on this pin enables RD’ & WR’ communication between the CPU and
the 8259A. This pin is connected to address bus through the decoder logic
circuit. Interrupt acknowledge functions to transfer the control to interrupt
service subroutine are independent of CS.
WR’ (Write signal): When CS’ is low enables the 8259 A to accept command
words from CPU.
RD’(Read signal): When CS’ is low enables this 8259A to release status
(pending interrupts or in-service interrupts or masked interrupts) on to the
data bus for the CPU. The status includes the contents of IMR (interrupt
mask register) or ISR (interrupt service register) or IRR (interrupt request
register) or a priority level.
14 GND Ground
27 A0 Address input
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 101
Fig 4.3: Pin Configuration of Intel 8259A
D7-D0 (Data Bus): Bidirectional data bus. Control, status and interrupt
vector information is transferred via this data bus. This bus is connected to
BDB of 8086.
CAS2-CAS0 (Cascade lines): The CAS lines form a local 8259A bus to
control multiple 8259As in master-slave configuration, i.e., to identify a
particular slave 8259A to be accessed for transfer of vector information.
These pins are automatically set as output pins for master 8259A and input
pins for a slave 8259A once the chips are programmed as master or slave.
In buffered mode, normally data bus buffers are used. These buffers need to
be enabled or disabled during transfer of vector information depending upon
whether 80259A is connected before the buffer or after the buffer. To
disable/enable the data bus transceivers (buffers) when data are being
transferred from the 8259A to the CPU, this pin is made low or high.
INT (Interrupt output): This pin goes high whenever a valid interrupt
request is asserted. It is used to interrupt the CPU, thus it is connected to
the CPU’s interrupt pin (INTR). In case of master-slave configuration, the
interrupt pin of slave 8259A is connected to interrupt request input of
master 8259A.
A0 (A0 address line): This pin acts in conjunction with the RD’ &CS’ pins.
It is used to send various command words from the CPU and to read the
status. It is normally connected to the CPU A0 address line. Two addresses
are assigned/reserved in the I/O address space for each 8259A in the
system-one with A0=0 is called even address and other with A0 = 1 is called
odd address.
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 102
Functional Description of 8259A: 8259A is used to manage the interrupt
requirement of the system. It has 8 interrupt input lines through which it
accepts interrupt requests from external devices and determines the priority
of the incoming request and issues an interrupt to the CPU. The interrupt
inputs are extendable up to 64 levels. And subsequently inputs information
related to ISR so that the processor can initialize the program counter with
the ISR address of the interrupting device. It is programmed as an I/O
device and provides number of interrupt modes to the programmer so that
the manner in which the requests are processed by 8259 can be configured
to match the system requirement. Figure below shows the functional
diagram of 8259A.
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 103
Interrupt Request register (IRR) and In-Service register (ISR): The
interrupt requests from the external devices IRQ lines are handled by these
two registers in cascade. IRR is used to latch the incoming request and, in
conjunction with priority resolver, allows unmasked requests with sufficient
priority to put a ‘1’ on the INT pin. ISR is used to store all the interrupts
that are being serviced by the CPU.
Priority resolver: The logic block determines the priority of the services
being in-request in the Interrupt Request Register. The highest priority is
selected and sent to the ISR during INTA pulse.
Read/Write Control Logic: The function of the R/W logic is to accept the
commands from the CPU. It consists of an initialization Command Word
(ICW) registers and Operation Command register (OCW) registers which
store various control formats. It also allows the status of 8259 to be
transferred to data bus. It has the following control signals:
Chip Select (CS’): It is a low active signal is used to select the chip. No
operation is possible until Chip is selected through this input.
Write (WR’) and Read (RD’): These are two low active signal used for read
and write operations. WR is used to write control words (ICWs and OCWs) to
8259A and read (RD’) is used to read the status information of IRR, ISR,
IMR or the interrupt level to the data bus.
Address input (A0): The Address input A0 from the processor can be
directly connected to A0 pin of 8259A and is used with RD’ and WR’ to write
commands and to select various status registers for read operation.
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 104
(SP’/EN’ = 0), or as an output to disable the data bus transceiver when data
are being transferred from the 8259A to the CPU.
CAS0 – CAS2 Cascade Lines: This block is of importance when more than
eight interrupts are to be used. This allows multiple 8259A to be cascaded
for this purpose.In cascade mode, a master 8259A along with eight slaves
8259A can provide up to 64 vectored interrupt lines. These three lines act as
select lines for addressing the slave 8259A. CAS0-to-CAS2 is outputs from
8259A when used as master and are inputs when used as slave. As a
master, 8259A sends the IDs of the interrupting slave device onto the CAS0-
CAS2 lines. The selected slave device will send its preprogrammed
subroutine address onto the data bus during the next one or two
consecutive INTA’ pulses.
The device 8259A can be interfaced with any CPU using either Polling or
Interrupt. In polling, the CPU keeps on checking each peripheral device in
sequence to ascertain if it requires any service from the CPU. If any such
service request is noticed, the CPU serves the request and then goes on to
the next device in sequence. The command words are sent to an 8259A to
initialize it. The flow chart is shown for the ICW1 and an ICW2 and sent to
any 8259A in the system. If the system has any slave 8259As (cascade
mode), then an ICW3 must be sent to the master and a different ICW must
be sent to the slave. The 8259A must be initialized by writing two to four
command words into the respective command word registers. These are
called as initialized command words. If A0 = 0 and D4 = 1, the control word
is recognized as ICW1. It contains the control bits for edge/level triggered
mode, single/cascade mode, call address interval and whether ICW4 is
required or not
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 105
ICW1 – Interrupt Trigger Type/ Address Interval/ Cascade? / With ICW4?
ICW2–Selects Base Vector Address 00001000 (0x08) for PIC1 and 01110000
(0x70) for PIC2
ICW4 – The only thing we must set is 8086/8080 Mode which is done using
Bit 0.
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 106
2 1 Call Address Interval of 4
ADI(for 8085) 0 Call Address Interval of 8
1 1 Single PIC
SNGL 0 Cascaded PICs
0 1 Will be Sending ICW4
0 Don't need ICW4
7 6 5 4 3 2 1 0
Filled from bit 7-3 of the 2nd byte Bit 2-0 are set according to the level of
output by the CPU during the the interrupt request
initialization of 8259A
IR6 would cause bit 2-0 to 110 and so on
Bit Function
7 IR7 is connected to a Slave
6 IR6 is connected to a Slave
5 IR5 is connected to a Slave
4 IR4 is connected to a Slave
3 IR3 is connected to a Slave
2 IR2 is connected to a Slave
1 IR1 is connected to a Slave
0 IR0 is connected to a Slave
For Slave:
Bit(s) Function
7 Reserved. Set to 0
6 Reserved. Set to 0
5 Reserved. Set to 0
4 Reserved. Set to 0
3 Reserved. Set to 0
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 107
2:0 Slave ID
000 Slave 0
001 Slave 1
010 Slave 2
011 Slave 3
100 Slave 4
101 Slave 5
110 Slave 6
111 Slave 7
Initialization Command Word 4 (ICW4) : ICW4 is output to only if IC4
(ICW1) is set to 1; otherwise, the content of ICW4 is cleared. The bits in
ICW4 are as follows
Bit(s) Function
7 Reserved. Set to 0
6 Reserved. Set to 0
5 Reserved. Set to 0
4 1 Special Fully Nested Mode
SFNM 0 Not Special Fully Nested Mode
3:2 0x Non - Buffered Mode
BUF:M/S (1/0) 10 Buffered Mode - Slave
11 Buffered Mode - Master
1 1 Auto EOI
AEOI 0 Normal EOI
0 1 8086/8080 Mode If 1, the ISR bit that caused the interrupt is cleared at the
uPM end of 2nd INTA’ pulse
0 MCS-80/85
OCW2 and OCW3 are used for controlling the mode of the 8259A and
receiving EOI commands.
Both OCW2 & OCW3 are distinguished from ICW1, which also uses even
address, by the content f bit-4 of data byte.
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 108
If content of bit-4 of data byte is 0, then byte is put in OCW2 or OCW3
according to bit-3. There is no ambiguity in ICW2, ICW3, ICW4 and OCW1
all using the odd address because initialization word must always follow
ICW1 as dictated by initialization sequence.
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 109
Interrupt Sequence of 8259A: The addressing capability allows direct or
indirect jumping to specific ISR based on the interrupt number and the
interrupting device. The normal sequence of events during an interrupt
depends on the type of the CPU used and are given below:
i. One or more IR lines (IR7±0) are raised high, setting the corresponding
IRR bit(s).
ii. The 8259A evaluates these requests, and sends an INT to the CPU, if
appropriate.
iii. After a bit in the IRR is set to ‘1’ it is compared with the corresponding
mask bit in IMR. If the mask bit is 0, the request is passed to the
priority resolver, but if it is 1, the request is blocked.
iv. When an interrupt is input to the priority resolver its priority is
examined and. If according to the current state of the priority resolver
the interrupt is to be sent to the CPU, the INT line is activated.
v. Assuming that the IF flag in the CPU was set to 1, the CPU will enter
its interrupt sequence at the completion of the current instruction and
return two negative pulses over the INTA’ line
vi. Upon receiving the 1st INTA’ pulse, the IRR latches are disabled, so
that the IRR will ignore further signals on the IR7-IR0 lines. This state
is maintained until the end of the 2nd INTA’ pulse.
vii. The 1st INTA’ pulse will cause the appropriate ISR bits to be set and
the corresponding IRR bit to be cleared.
viii. The 8086 will initiate a second INTA’ pulse. During this pulse, the
8259A releases an 8-bit pointer onto the Data Bus where it is read by
the CPU. The current content of ICW2 to be placed on D7-D0, and the
CPU uses this byte as the interrupt type.
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 110
ix. Now if the automatic end of interrupt (AEOI) bit ICW4 is 1, at the end
of the second INTA’ pulse the ISR bit that was set by 1 st INTA’ pulse is
cleared; otherwise, the ISR bit is not cleared until the proper end of
interrupt (EOI)command is sent to OCW2
8086 Example: A typical program sequence for setting the content of ICWs,
which assume the even address of the 8259A is 0080h, is given below:
MOV AL, 13h; ICW1 indicating request to be edge trigger, use one
8259A, ICW4 to be output
OUT 80h, AL
OUT 81h
MOV AL, 0Dh ; informs the 8259A that SFNM is not to be used,
SP’/EN’ used to disable TXR, and ; 8259A is master,
EOI used to clear ISR bit, and 8259A is part of 8086
system
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 111
Mnemonics
MOV CX, 0000
MOV AX, [3000]
MOV BX, [3002]
ADD AX, BX
JNC 2010
INC CX
2010 MOV[3004], AX
MOV[3006], CX
INT 03
Problem – Write an ALP to add two 16 bit BCD numbers with carry in 8086
microprocessor.
Mnemonics Comments
MOV AL, [500] AL ← [500]
MOV BL, [502] BL ← [502]
ADD AL, BL AL ← AL+BL
DAA Decimal Adjust AL
MOV [600], AL AL → [600]
MOV AL, [501] AL ← [501]
MOV BL, 503 BL ← [503]
ADC AL, BL AL ← AL+BL+CY
DAA Decimal Adjust AL
MOV [601], AL AL → [601]
MOV AL, 00 AL ← 00H
ADC AL, AL AL ← AL+AL+CY
MOV [602], AL AL → [602]
INT 03 Stop Execution
Problem – Write an ALP to add the content of memory location 2000 : 0500
with content of memory location 3000 : 0600 and store result into 5000 :
0700 memory location.
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 112
MOV ES, CX
MOV[700], AX
INT 03
Problem – Write an ALP to find out the Subtraction of two 8-bit BCD
numbers, where numbers are stored from starting memory address 2000 :
500 and store the result into memory address 2000 : 600 and carry (borrow)
at 2000 : 601.
Problem – Write an ALP to find out the subtraction of two 16-bit BCD
numbers, where numbers are stored from starting offset 500 and store the
result into offset 600.
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 113
Problem – Write an ALP to subtract two 16-bit numbers where starting
address is 2000 and the numbers are at 3000 and 3002 memory address
and store result into 3004 and 3006 memory address.
Problem – Write an ALP to multiply two 8-bit numbers, where numbers are
stored from offset 500 and store the result into offset 600.
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 114
Memory Mnemonics Operands Comment
2014 HLT Stop
MNEMONICS COMMENT
MEMORY ADDRESS
0400 MOV SI, 500 SI <- 500
0403 MOV DI, 600 DI <- 600
0406 MOV BL, [SI] BL <- [SI]
0408 INC SI SI <- SI + 1
0409 MOV AX, [SI] AX <- [SI]
040B DIV BL AX <- AX / BL
040D MOV [DI], AX [DI] <- AX
040F HLT End of program
Problem – Write an ALP to find out the sum of series of even numbers,
where numbers are stored from starting offset 500 and store the result at
offset 600.
MEMORY
MNEMONICS COMMENT
ADDRESS
400 MOV SI, 500 SI<-500
403 MOV CL, [SI] CL<-[SI]
405 INC SI SI<-SI+1
406 MOV CH, 00 CH<-00
408 MOV AL, 00 AL<-00
40A MOV BL, [SI] BL<-[SI]
40C TEST BL, 01 BL AND 01
40F JNZ 413 JUMP IF NOT ZERO
411 ADD AL, BL AL<-AL+BL
413 INC SI SI<-SI+1
JUMP TO 40A IF CX NOT
414 LOOP 40A
ZERO
416 MOV [600], AL AL->[600]
41A HLT END
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 115
Address Mnemonics Comments
MOV SI, 500 SI<-500
MOV CL, [SI] CL<-[SI]
INC SI SI<-SI+1
MOV CH, 00 CH<-00
MOV AL, 00 AL<-00
MOV BL, [SI] BL<-[SI]
TEST BL, 01 BL.01
JZ 413 Jump to 413 memory location if zero flag is set
ADD AL, BL AL<-AL+BL
413 INC SI SI<-SI+1
jump to 40A memory location if content of CX is not
LOOP 40A
equal to zero
MOV [600],
[600], AL
AL
HLT end
MNEMONICS COMMENTS
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 116
MNEMONICS COMMENTS
MOV CX, [0500] CX <- [0500]
MOV AX, 0001 AX <- 0001
MOV DX, 0000 DX <- 0000
MUL CX DX:AX <- AX * CX
LOOP 040A Go To [040A] till CX->00
MOV [0600], AX [0600]<-AX
MOV [0601], DX [0601]<-DX
HLT Stop Execution
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 117
Interface diagram
Dr.Sreenivasa Rao Ijjada, Dept of ECE,GIT, GITAM University Visakhapatnam. Page 118