Unit 2 Microprocessor Course Material
Unit 2 Microprocessor Course Material
Unit 2 Microprocessor Course Material
INTEL 8086
AD0-AD15
1
These lines are multiplexed bidirectional address/data bus. During T1, they carry
lower order 16-bit address. In the remaining clock cycles,they carry 16-bit data.
AD0-AD7 carry lower order byte of data. AD8-AD15 carry higher order byte of data.
RESET[Pin 21 (Input)]
It is a system reset. It is an active high signal. When high, microprocessor enters
into reset state and terminates the current activity. It must be active for atleast four
clock cycles to reset the microprocessor.
NMI[Pin 17 (Input)]
It is a non-maskable interrupt signal. It is an active high. It is an edge
triggeredinterrupt.
TEST[Pin 23 (Input)]
It is used to test the status of math coprocessor 8087. The BUSY pin of 8087
isconnected to this pin of 8086. If low, execution continues else microprocessor is in
wait state.
CLK[Pin 19 (Input)]
This clock input provides the basic timing for processor operation. It is symmetric
square wave with 33% duty cycle. The range of frequency of different versions is 5
MHz, 8 MHz and 10 MHz.
MN / MX[Pin 33 (Input)]
2
8086 works in two modes: Minimum Mode, Maximum Mode. If MN/MX is high, it
worksin minimum mode. If MN/MX is low, it works in maximum mode. Pins 24 to 31
issue twodifferent sets of signals. One set of signals is issued when CPU operates
in minimum mode. Other set of signals isissued when CPU operates in maximum
mode.
DEN[Pin 26 (Output)]
This is a Data Enable signal. This signal is used toenable the transceiver 8286.
Transceiver is used to separate the data from the address/data bus. It is an
active low signal
DT / R[Pin 27 (Output)]
This is a DataTransmit/Receive signal. It decides the direction ofdata flow
through the transceiver. When it is high, data is transmitted out. When it is low,
data is received in.
M / IO[Pin 28 (Output)]
This signal is issued by the microprocessor to distinguish memory access from
I/O access. When it is high, memory is accessed. When it is low, I/O devices are
accessed.
WR [Pin 29 (Output)]
It is a Write signal. It is used to write data inmemory or output device depending
on the status of M/IO signal. It is an active low signal
HLDA[Pin 30 (Output)]
It is a Hold Acknowledge signal. It is issued after receiving the HOLD signal. It
is an active high signal
HOLD[Pin 31 (Input)]
When DMA controller needs to use address/data bus, it sends a request to the
CPU through this pin. It is an active high signal. When microprocessor receives
HOLD signal, it issues HLDA signal to the DMA controller.
3
These pins provide the status of instruction queue.
S0 S1 S2 STATUS
0 0 0 Interrupt Acknowledge
0 0 1 I/O Read
0 1 0 I/O Write
0 1 1 Halt
1 0 0 Opcode Fetch
1 0 1 Memory Read
1 1 0 Memory Write
1 1 1 Passive
LOCK[Pin 29 (Output)]
This signal indicates that other processors should not ask CPU to relinquish the
system bus. When it goes low, all interrupts are masked and HOLD request is
not granted. This pin is activated by using LOCK prefix on any instruction.
Architecture of 8086
The microprocessors functions as the CPU in the stored program model of the digital
computer. Its job is to generate all system timing signals and synchronize the
transfer of data between memory, I/O, and itself. The microprocessor also has a S/W
function. It must recognize, decode, and execute program instructions fetched from
the memory unit. This requires an Arithmetic-Logic Unit (ALU) within the CPU to
perform arithmetic and logical (AND, OR, NOT, compare, etc) functions.
The 8086 has pipelined architecture. The 8086 CPU is organized as two separate
processors, called the Bus Interface Unit (BIU) and the Execution Unit (EU).
4
A : Address Bus
D :Databus
Q : Q Bus
5
Fig : Architecture of 8086
Instruction Queue
1. To increase the execution speed, BIU fetches as many as six instruction bytes
ahead to time from memory.
2. All six bytes are then held in first in first out 6 byte register called instruction
queue.
4. This pre fetching operation of BIU may be in parallel with execution operation of
EU, which improves the speed execution of the instruction.
These registers can be used as 8-bit registers individually or can be used as 16-bit
in pair to have AX, BX, CX, and DX.
6
2. BX Register: This register is mainly used as a base register. It holds the starting
base location of a memory region within a data segment.
4. DX Register: DX register is used to contain I/O port address for I/O instruction.
Segment Registers :
7
Flag Registers of 8086
Flag Register determines the current state of the processor. They are modified
automatically by CPU after mathematical operations, this allows to determine the
type of the result, and to determine conditions to transfer control to other parts of the
program. 8086 has 9 flags and they are divided into two categories:
1. Conditional Flags
2. Control Flags
Conditional Flags
Carry Flag (CF): 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.
Overflow Flag (OF): It occurs when signed numbers are added or subtracted. An
OF indicates that the result has exceeded the capacity of machine.
Control Flags
8
Control flags are set or reset deliberately to control the operations of the execution
unit. Control flags are as follows:
c. When trap flag is set, program can be run in single step mode.
b. If it is set, the maskable interrupt of 8086 is enabled and if it is reset, the interrupt
is disabled.
c. It can be set by executing instruction sit and can be cleared by executing CLI
instruction.
b. If it is set, string bytes are accessed from higher memory address to lower
memory address.
c. When it is reset, the string bytes are accessed from lower memory address to
higher memory address.
9
10) Direct I/O port Addressing
11) Indirect I/O port Addressing
10
If [DS]=5004(16),then
2000H BX 5004
02H Displacement 2 0 0 2 EA
2002H EA 5 2 0 4 0 20 bit Physical Address
Here the source operand is in based Addressing Mode.EA is obtained by adding the
value of START and [BX].The 20 bit physical address is produced from DS and
EA.The 8 bit content of this memory location is moved to AL register.
Moves the contents of the 20 bit address computed from the displacement START,SI
and DS into BH register.The 8 bit displacement is provided by the programmer using
the assembler pseudoindtruction such as EQU.For 16 bit displacement,the EU adds
this to SI to determine EA.On the other hand,for 8 bit displacement the EU sign
extends it to 16 bits and then adds to SI for determining EA.
String Addressing
11
The segment register for the source is DS and may be overridden.The segment
register for the destination must be ES and cannot be overridden.
Here the port number is a 8 bit immediate operand.This allows fixed access to ports
numbered 0 to 255.
The port number is taken from DX allowing 64K 8 bit ports or 32K 16 bit ports.
eg:- IN AX,DX
If [DX]=5040,Inputs the 8 bit content of port 5040 into AL and 5041 into AH.
then,if carry=0,PC is loaded with current PC contents plus the 8 bit signed value of
START,otherwise the next instruction is executed.
eg:- CLC
12
location. The source can be a register, a memory location or an immediate
number. The source and destination cannot both be memory locations. They
must both be of the same type (bytes or words).MOV instruction does not
affect any flag.
MOV ES: RESULTS [BP], AX Same as the above instruction, but physical
address = EA + ES, because of the segment
override prefix ES
The XCHG instruction exchanges the content of a register with the content
of another register or with the content of memory location(s). It cannot
directly exchange the content of two memory locations. The source and
destination must both be of the same type (bytes or words). The segment
registers cannot be used in this instruction. This instruction does not affect
any flag.
This instruction 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.
13
LEA BP, SS: STACK_TOP Load BP with offset of STACK_TOP
in SS
This instruction 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.
This instruction 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.
LES DI, [BX] Copy content of memory at offset [BX] and offset
[BX] + 1 in DS to DI register. Copy content of
memory at offset [BX] + 2 and [BX] + 3 to ES
register.
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 generalpurpose 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 instruction does not affect any flag.
14
PUSH BX Decrement SP by 2, copy BX to stack.
PUSH DS Decrement SP by 2, copy DS to stack.
PUSH BL Illegal; must push a word
PUSH TABLE [BX] Decrement SP by 2, and copy word from memory
in DS at EA = TABLE + [BX] to stack
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
The IN instruction copies data from a port to the AL or AX register. If an 8-bit port is
read, the data will go to AL. If a 16-bit port is read, the data will go to AX.
The IN instruction has two possible formats, fixed port and variable port. For fixed
port type, the 8-bit address of a port is specified directly in the instruction. With this
form, any one of 256 possible ports can be addressed.
15
IN AL, OC8H Input a byte from port OC8H to AL
IN AX, 34H Input a word from port 34H to AX
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 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.
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.
16
ADD – ADD Destination, Source
These instructions add a number from some source to a number in some destination
and put the result in the specified destination. The ADC also adds the status of the
carry flag to the result. The source may be an immediate number, a register, or a
memory location. The destination may be a register or a memory location. The
source and the destination in an instruction cannot both be memory locations. The
source and the destination must be of the same type (bytes or words). If you want to
add a byte to a word, you must copy the byte to a word location and fill the upper
byte of the word with 0’s before adding. Flags affected: AF, CF, OF, SF, ZF.
ADD AL, 74H Add immediate number 74H to content of AL. Result in
AL
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 [BX] plus carry status to
content of AL
ADD AL, PRICES [BX] Add content of memory at effective address PRICES [BX]
to AL
These instructions subtract the number in some source from the number in some
destination and put the result in the destination. The SBB instruction also subtracts
the content of carry flag from the destination. The source may be an immediate
number, a register or memory location. The destination can also be a register or a
memory location. However, the source and the destination cannot both be memory
location. The source and the destination must both be of the same type (bytes or
words). If you want to subtract a byte from a word, you must first move the byte to a
word location such as a 16-bit register and fill the upper byte of the word with 0’s.
Flags affected: AF, CF, OF, PF, SF, ZF.
17
SUB AX, 3427H Subtract immediate number 3427H from AX
SUB PRICES [BX], 04H Subtract 04 from byte at effective address PRICES [BX],
if PRICES is declared with DB; Subtract 04 from word at
effective address PRICES [BX], if it is declared with DW.
SBB CX, TABLE [BX] Subtract word from effective address TABLE [BX] and
status of CF from CX.
This instruction multiplies an unsigned byte in some source with an unsigned byte in
AL register or an unsigned word in some source with an unsigned word in AX
register. The source can be a register or a memory location. When a byte is
multiplied by the content of AL, the result (product) is put in AX. When a word is
multiplied by the content of AX, the result is put in DX and AX registers. If the most
significant byte of a 16-bit result or the most significant word of a 32-bit result is 0,
CF and OF will both be 0’s. AF, PF, SF and ZF are undefined after a MUL
instruction.
If you want to multiply a byte with a word, you must 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.
You 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.
MUL CX Multiply AX with CX; result high word in DX, low word in AX
MUL FACTOR [BX] Multiply AL with byte at effective address FACTOR [BX],
if it is declared as type byte with DB. Multiply AX with word at
effective address FACTOR [BX], if it is declared as type word
with DW.
MOV AX, MCAND_16 Load 16-bit multiplicand into AX MOV CL, MPLIER_8
Load 8-bit multiplier into CL MOV CH, 00H Set upper byte of
CX to all 0’s MUL CX AX times CX; 32-bit result in DX and AX
18
This instruction multiplies a signed byte from source with a signed byte in AL or a
signed word from some source with a signed word in AX. The source can be a
register or a memory location. When a byte from source is multiplied with content of
AL, the signed result (product) will be put in AX. When a word from source is
multiplied by AX, the result is put 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 and the OF will
both be 0; If it contains a part of the product, CF and OF will both be 1. AF, PF, SF
and ZF are undefined after IMUL.
If you want to multiply a signed byte with a signed word, you must first move the byte
into a word location and fill the upper byte of the word with copies of the sign bit. If
you move the byte into AL, you can use the CBW instruction to do this.
If you want to divide a byte by a byte, you must first put the dividend byte in AL and
fill AH with all 0’s. Likewise, if you want to divide a word by another word, then put
the dividend word in AX and fill DX with all 0’s.
19
DIV CX Divide down word in DX and AX by word in CX; Quotient in AX,
and remainder in DX.
DIV SCALE [BX] AX / (byte at effective address SCALE [BX]) if SCALE [BX] is of
type byte; or (DX and AX) / (word at effective address
SCALE[BX] if SCALE[BX] is of type word
When dividing a signed word by a signed byte, the word must be in the AX register.
The divisor can be in an 8-bit register or 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 automatically generate a type 0 interrupt.
If you want to divide a signed byte by a signed byte, you must first put the dividend
byte in AL and signextend AL into AH. The CBW instruction can be used for this
purpose. Likewise, if you want to divide a signed word by a signed word, you must
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.
The INC instruction adds 1 to a specified register or to a memory location. AF, OF,
PF, SF, and ZF are updated, but CF is not affected. This means that if an 8-bit
destination containing FFH or a 16-bit destination containing FFFFH is incremented,
the result will be all 0’s with no carry.
20
INC BL Add 1 to contains of BL register
INC BYTE PTR [BX] Increment byte in data segment at offset contained
in BX.
INC WORD PTR [BX] Increment the word at offset of [BX] and [BX + 1] in the
data segment.
This instruction subtracts 1 from the destination word or byte. The destination can be
a register or a memory location. AF, OF, SF, PF, and ZF are updated, but CF is not
affected. This means that if an 8-bit destination containing 00H or a 16-bit destination
containing 0000H is decremented, the result will be FFH or FFFFH with no carry
(borrow).
DEC BYTE PTR [BX] Subtract 1 from byte at offset [BX] in DS.
DEC WORD PTR [BP] Subtract 1 from a word at offset [BP] in SS.
This instruction is 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.
21
ADD AL, BL AL = 8EH; lower nibble > 9, add 06H to AL
DAA AL = 94 BCD, CF = 0
AL = 37 BCD, CF = 1
The DAA instruction updates AF, CF, SF, PF, and ZF; but OF is undefined.
This instruction is 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.
AL = 29 BCD, CF = 0
The DAS instruction updates AF, CF, SF, PF, and ZF; but OF is undefined.
This instruction 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.
22
This instruction copies the sign bit of a word in AX to all the bits of the DX register. In
other words, it extends the sign of AX into all of DX. CWD affects no flags.
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 you 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.
Numerical data coming into a computer from a terminal is usually in an ASCII code.
In this code the numbers 0 to 9 are represented by the ASCII codes 30H to 39H. The
8086 allows you to subtract the ASCII codes for two decimal digits without masking
the “3” in the upper nibble of each. The AAS instruction is then used to make sure
the result is the correct unpacked BCD.
The AAS instruction works only on the AL register. It updates ZF and CF; but OF,
PF, SF, AF are left undefined.
23
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.
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.
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.
The source can be an immediate number, the content of a register, or the content
of a memory location. The destination can be a register or a memory location.
The source and the destination cannot both be memory locations. CF and OF are
both 0 after AND. PF, SF, and ZF are updated by the AND instruction. AF is
undefined. PF has meaning only for an 8-bit operand.
24
AND CX, [SI] AND word in DS at offset [SI] with word in CX register;
Result in CX register
AND BX, 00FFH 00FFH Masks upper byte, leaves lower byte unchanged.
OR – OR Destination, Source
This instruction 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.
The source can be an immediate number, the content of a register, or the content
of a memory location. The destination can be a register or a memory location.
The source and destination cannot both be memory locations. CF and OF are
both 0 after OR. PF, SF, and ZF are updated by the OR instruction. AF is
undefined. PF has meaning only for an 8-bit operand.
OR CX, TABLE [SI] CX ORed with word from effective address TABLE [SI];
Content of memory is not changed.
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.
The source can be an immediate number, the content of a register, or the content
of a memory location. The destination can be a register or a memory location.
The source and destination cannot both be memory locations. CF and OF are
both 0 after XOR. PF, SF, and ZF are updated. PF has meaning only for an 8-bit
operand. AF is undefined.
25
XOR WORD PTR [BX], 00FFH Exclusive-OR immediate number 00FFH
with word at offset [BX] in the data segment.
Result in memory location [BX]
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.
This instruction replaces the number in a destination with its 2’s complement. The
destination can be a register or a memory location. It gives the same result as the
invert each bit and add one algorithm. The NEG instruction updates AF, AF, PF,
ZF, and OF.
NEG BYTE PTR [BX] Replace byte at offset BX in DX with its 2’s
complement NEG WORD PTR [BP] Replace word at offset BP in
SS with its 2’s complement
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:
26
CF ZF SF
CX = BX 0 1 0 Result of subtraction is 0
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.
The source can be an immediate number, the content of a register, or the content
of a memory location. The destination can be a register or a memory location.
The source and the destination cannot both be memory locations. CF and OF are
both 0’s after TEST. PF, SF and ZF will be updated to show the results of the
destination. AF is be undefined.
TEST AL, BH AND BH with AL. No result stored; Update PF, SF,
ZF.
TEST BP, [BX][DI] AND word are offset [BX][DI] in DS with word in
BP. No result stored. Update PF, SF, and ZF
This instruction rotates all the bits in a specified word or byte 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.
27
For multi-bit rotates, CF will contain the bit most recently rotated out of the MSB.
The destination can be a register or a memory location. If you want to rotate the
operand by one bit position, you can specify this by putting a 1 in the count
position of the instruction. To rotate by more than one bit position, load the
desired number into the CL register and put “CL” in the count position of the
instruction.
RCL affects only CF and OF. OF will be a 1 after a single bit RCL if the MSB was
changed by the rotate. OF is undefined after the multi-bit rotate.
This instruction rotates all the bits in a specified word or byte 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.
The destination can be a register or a memory location. If you want to rotate the
operand by one bit position, you can specify this by putting a 1 in the count
position of 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.
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.
28
RCR BYTE PTR [BX], 4 Rotate the byte at offset [BX] in DS 4 bit
positions right CF = original bit 3, Bit 4 – original
CF.
This instruction rotates all the bits in a specified word or 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 or a memory location. If you to want rotate the
operand by one bit position, you can 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
This instruction rotates all the bits in a specified word or 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.
29
in the instruction. To rotate by more than one bit position, load the desired number
into the CL register and put “CL” in the count position of the instruction.
ROR affects only CF and OF. OF will be a 1 after a single bit ROR if the MSB
was changed by the rotate.
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.
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.
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
30
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
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.
31
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.
This instruction copies a byte or a word from location in the data segment to a
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.
MOV SI, OFFSET SOURCE Load offset of start of source string in
DS into SI MOV DI, OFFSET DESTINATION Load offset of start of
destination string in ES into DI CLD Clear DF
to auto increment SI and DI after move MOV CX, 04H
Load length of string into CX as counter
REP MOVSB Move string byte until CX = 0
32
This instruction copies a byte from a string location pointed to by SI to AL, or a word
from a string location pointed to by SI to AX. If DF is 0, SI will be automatically
incremented (by 1 for a byte string, and 2 for a word string) to point to the next
element of the string. If DF is 1, SI will be automatically decremented (by 1 for a byte
string, and 2 for a word string) to point to the previous element of the string. LODS
does not affect any flag.
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.
This instruction copies a byte from AL or a word from AX to a memory location in the
extra segment pointed to by DI. In effect, it replaces a string element with a byte from
AL or a word from AX. After the copy, DI is automatically incremented or
decremented to point to next or previous element of the string. If DF is cleared, then
DI will automatically incremented by 1 for a byte string and by 2 for a word string. If
DI is set, DI will be automatically decremented by 1 for a byte string and by 2 for a
word string. STOS does not affect any flag.
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.
33
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.
The following program segment scans a text string of 80 characters for a carriage
return, 0DH, and puts the offset of string into DI:
34
MOV CX, 80 CX used as element counter
CLD Clear DF, so that DI auto increments
REPNE SCAS STRING Compare byte in string with byte in AL
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.
REPNE SCASW Scan a string of word until a word in the string matches the word
in AX or until all of the string has been scanned.
The string instruction used with the prefix determines which flags are affected.
This instruction will fetch the next instruction from the location specified in the
instruction rather than from the next location after the JMP instruction. 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. 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
35
content will be changed to get the destination location. This referred to as a
far jump. The JMP instruction does not affect any flag.
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 carry flag
is 0, this instruction will cause execution to jump to a label given in the
instruction. If CF is 1, the instruction will have no effect on program execution.
36
JB / JC / JNAE (JUMP IF BELOW / JUMP IF CARRY / JUMP IF NOT ABOVE OR
EQUAL)
If, after a compare or some other instructions which affect flags, the carry flag
is a 1, this instruction will cause execution to jump to a label given in the
instruction. If CF is 0, the instruction will have no effect on program execution.
If, after a compare or some other instructions which affect flags, either the
zero flag or the carry flag is 1, this instruction will cause execution to jump to a
label given in the instruction. If CF and ZF are both 0, the instruction will have
no effect on program execution.
JGE / JNL (JUMP IF GREATER THAN OR EQUAL / JUMP IF NOT LESS THAN)
37
This instruction is usually used after a Compare instruction. The instruction
will cause a jump to the label given in the instruction, if the sign flag is equal to
the overflow flag.
This instruction is usually used after a Compare instruction. The instruction will
cause a jump to the label given in the instruction if the zero flag is set, or if the sign
flag not equal to the overflow flag.
This instruction is usually used after a Compare instruction. If the zero flag is set,
then this instruction will cause a jump to the label given in the instruction.
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.
38
This instruction will cause a jump to the specified destination address if the sign flag
is set. Since a 1 in the sign flag indicates a negative signed number, you can think of
this instruction as saying “jump if negative”.
This instruction will cause a jump to the specified destination address if the sign flag
is 0. Since a 0 in the sign flag indicate a positive signed number, you can think to this
instruction as saying “jump if positive”.
DEC AL Decrement AL
JNS NEXT Jump to label NEXT if AL has not decremented to FFH
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 parity flag will be set. 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.
JO (JUMP IF OVERFLOW)
The overflow flag will be set if the magnitude of the result produced by some signed
arithmetic operation is too large to fit in the destination register or memory location.
39
The JO instruction will cause a jump to the destination given in the instruction, if the
overflow flag is set.
The overflow flag will be set if some signed arithmetic operation is too large to fit in
the destination register or memory location. The JNO instruction will cause a jump to
the destination given in the instruction, if the overflow flag is not set.
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.
This instruction is used to repeat a series of instructions some number of times. 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 is
not 0, execution will jump to a destination specified by a label in the instruction. If CX
= 0 after the auto decrement, execution will simply go on to the next instruction after
LOOP. 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 LOOP instruction. This
instruction does not affect any flag.
40
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.
41
A RET instruction at the end of the procedure will return execution to the offset
saved on the stack which is copied back to IP. 2. A far call is a call to a procedure,
which is in a different segment from the one that contains the CALL instruction.
When the 8086 executes a far call, it decrements the stack pointer by 2 and copies
the content of the CS register to the stack. It then decrements the stack pointer by 2
again and copies the offset of the instruction after the CALL instruction to the stack.
Finally, it loads CS with the segment base of the segment that contains the
procedure, and loads IP with the offset of the first instruction of the procedure in that
segment. A RET instruction at the end of the procedure will return execution to the
next instruction after the CALL by restoring the saved values of CS and IP from the
stack.
CALL MULT
This is a direct within segment (near or intra segment) call. MULT is the name
of the procedure. The assembler determines the displacement of MULT from
the instruction after the CALL and codes this displacement in as part of the
instruction.
CALL BX
This is an indirect within-segment (near or intra-segment) call. BX contains
the offset of the first instruction of the procedure. It replaces content of IP with
content of register BX.
CALL DIVIDE
This is a direct call to another segment (far or inter-segment call). DIVIDE is
the name of the procedure. The procedure must be declared far with DIVIDE
PROC FAR at its start. The assembler will determine the code segment base
for the segment that contains the procedure and the offset of the start of the
procedure. It will put these values in as part of the instruction code.
42
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.
A RET instruction can be followed by a number, for example, RET 6. In this case, the
stack pointer will be incremented by an additional six addresses after the IP when
the IP and CS are popped off the stack. This form is used to increment the stack
pointer over parameters passed to the procedure on the stack.
43
This instruction resets the interrupt flag to 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.
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 up 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.
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.
PROCEDURE
Procedure is a part of code that can be called from your program in order to make
some specific task. Procedures make program more structural and easier to
understand. Generally procedure returns to the same point from where it was called.
The syntax for procedure declaration:
name PROC
; here goes the code
; of the procedure
.
.
RET
name ENDP
44
name - is the procedure name, the same name should be in the top and the bottom,
this is used to check correct closing of procedures.
ASSEMBLER DIRECTIVES
PROC
ENDP
PROC and ENDP are compiler directives, so they are not assembled into any real
machine code. Compiler just remembers the address of procedure. CALL instruction
is used to call a procedure.
ORG
ORG 100h is a compiler directive (it says to compiler how to handle the source
code). This directive is very important when you work with variables. It says to
compiler that the executable file will be loaded at the offset of 100h (256 bytes), so
compiler should calculate the correct address for all variables when it replaces the
variable names with their offsets. Directives are never converted to any real machine
code.
ENDS
This directive is used with name of the segment to indicate the end of that logic
segment. For example
ASSUME
This directive tells the assembler the name of the logical segment it should use for a
specified segment. For example ASSUME CS:CODE, tells the assembler that the
instructions for a program are in a logical segment named CODE. The 8086 works
directly with only 4 physical segments: a Code segment, a data segment, a stack
segment, and an extra segment.
8086 PROGRAMS
Program for find the ADDITION of two Program for find the SUBTRACTION
numbers: of two numbers:
45
ADD AX,BX SUB AX,BX
INT 03 INT 03
Program for find the Program for find the DIVISION of two
MULTIPLICATION of two numbers: numbers:
MUL BX DIV BX
INT 03 INT 03
Program for find the GREATEST OF 2- Program for find the AVERAGE OF N-
NUMBERS: NUMBERS:
DIV CX
MOV [DI],AX
INT 03
Program for find the SUM OF N- Program for find the find the factorial
NUMBERS: of a number
46
MOV SI,8000 MOV SI,8000
MOV [DI],AX
INT 03
47
Fig: Pin diagram of 8284
Pin Functions:
The 8284A is an 18-pin integrated circuit designed specifically for use with the
8086/8088 microprocessors as shown in fig1. The following is a list of each pin and
its function.
The address enable pins are provided to qualify the ready signals. RDY1 and RDY2,
respectively. Which are used to cause wait states, along with the RDY1 and RDY2
inputs. Wait states are generated by the READY pin of the 8086/8088
microprocessor. This is controlled by these two inputs.
The bus ready inputs are provided in conjunction with the AEN1* and AEN2* pins to
cause wait states in an 8086/8088 microprocessor based system.
ASYNC*:
The ready synchronization selection input selects either one or two stages of
synchronization for the RDY1 and RDY2 inputs.
READY:
48
Ready is an output pin that connects to the 8086/8088 microprocessor READY input.
This signal is synchronized with the RDY1 and RDY2 inputs.
X1 and X2:
The Crystal Oscillator pins connect to an external crystal used as the timing source
for the clock generator and all its functions.
F/C*:
The Frequency/Crystal select input results the clocking source for the 8284A. If this
pin is held high, an external clock is provided to the EFI input pin, and if it is held low,
the internal crystal oscillator provides the timing signal.
EFI:
The External Frequency input is used when the F/C is pulled high. EFI supplies the
timing whenever the F/C* pin is high..
CLK:
The clock output pin provides CLK input signal to the 8086/8088 microprocessors
and other components in the system. The CLK pin has an output signal that is one-
third of the crystal or EFI input frequency and has a 33 percent duty cycle, which is
required by the 8086/8088 microprocessors.
PCLK:
The Peripheral Clock signal is one-sixth the crystal or EFI input frequency and has a
50 percent duty cycle. The PCLK output provides a clock signal to the peripheral
equipment in the system.
OSC:
The Oscillator output is a TTL level signal that is at the same frequency as the
crystal or EFI input. (The OSC output provides and EFI input to other 8284A clock
generators in some multiple processor systems).
RES*:
The reset input is an active-low input to the 8284A. The RES* pin is often connected
an RC network that provides power-on resetting.
RESET:
The Reset output is connected to the 8086/8088 microprocessors RESET input pin.
CSYNC:
49
The clock synchronization pin is used whenever the EFI input provides
synchronization in systems with multiple processors. When the internal crystal
oscillator is used, this pin must be grounded.
GND:
Vcc:
That F/C and CSYNC are grounded to select the crystal oscillator and that a 15
MHz crystal provides the normal 5 MHz clock signal to the 8086/8088 as well as a
2.5 MH-z peripheral clock signal.
Operation of the Reset Section: The reset section of the 8284A is simple, and it
consists of a Schmitt trigger buffer and a single D-type flip-flop circuit. The D-type
flip-flop ensures that the timing requirement of the 8086 RESET input are fulfilled.
This circuit applies the RESET signal to the microprocessor on the negative edge
(1-to-0 transition) of each clock. The 8086/8088 microprocessors sample RESET at
the positive edge (0-to- 1 transition) of the clocks; therefore (this circuit meets the
timing requirements of the 8086). From Fig. it can be observed that an RC circuit
provides a logic 0 to the RES input pin when power is first applied to the system.
After a short time, the RES input becomes a logic 1 because the capacitor charges
toward +5.0 V through the resistor. A push button switch allows the microprocessor
to be reset by the operator. Exact rest timing requires the RESET input to become a
logic 1 no later than four clocks after system power is applied and to be held for at
least 50 µs. (The flip-flop makes certain that RESET goes high in four clocks, and
the RC time constant ensures that it stays high for at least 50 µs).
50
UNIT IV
PART A
Answer the following
1. What are the differences between 8085 and 8086?
2. How is physical address calculated in 8086 microprocessor?
3. How many address and data lines are there in 8086 microprocessor?
4. What is the need for segment registers in 8086 microprocessor?
5. What are the advantages and disadvantages of pipelined architectures?
6. Draw the flag register of 8086 microprocessor.
7. What is an overflow flag?
8. What is the need for direction flag in 8086?
9. What is the use for trap flag in 8086?
10. What do you mean by minimum and maximum mode operations of 8086
microprocessor?
11. What is the purpose of LOCK in 8086?
12. What is the need for Request and Grant signals in 8086 microprocessor?
13. What is the purpose of 8284 clock driver?
14. What are pseudocodes?
15. With is the need for index registers in 8086 microprocessor?
16. What is the use of AAA instruction?
PART B
Answer the following
1. With a neat diagram, explain the architecture of 8086 microprocessor.
2. With a neat signal diagram, explain the minimum mode operation of 8086
microprocessor.
3. With a diagram, explain the maximum mode operations of 8086
microprocessor.
4. With a neat diagram, explain the working of 8284 clock driver.
5. What is an addressing mode? Describe the different types of addressing
modes with suitable examples.
6. Explain any two types of instructions in 8086 microprocessor.
7. Write an assembly language program to perform block transfer of data.
51