Unit-1 MMC 8086
Unit-1 MMC 8086
Introduction :
The 8086 microprocessor is an 16-bit microprocessor designed by Intel in the late 1970s. It is the first
member of the x86 families of microprocessors, which includes many popular CPUs used in personal
computers.
The architecture of the 8086 microprocessor is based on a complex instruction set computer (CISC)
architecture, which means that it supports a wide range of instructions, many of which can perform multiple
operations in a single instruction. The 8086 microprocessor has a 20-bit address bus, which can address up to
1 MB of memory, and a 16-bit data bus, which can transfer data between the microprocessor and memory or
I/O devices.
FUNCTIONAL UNITS: The 8086 microprocessor has two main execution units: the execution unit (EU)
and the bus interface unit (BIU). The BIU is responsible for fetching instructions from memory and decoding
them, while the EU executes the instructions. The BIU also manages data transfer between the
microprocessor and memory or I/O devices.
0 0 0 Interrupt acknowledge
0 1 1 Halt
S2 S1 S0 Characteristics
1 0 0 Code access
1 0 1 Read memory
1 1 0 Write memory
1 1 1 Passive state
A16/S3, A17/S4, A18/S5, A19/S6 : The specified address lines are multiplexed with corresponding
status signals.
HE’/S7: Bus High Enable/Status. During T1 it is low. It is used to enable data onto the most significant
half of data bus, D8-D15. 8-bit device connected to upper half of the data bus use BHE (Active Low)
signal. It is multiplexed with status signal S7. S7 signal is available during T2, T3 and T4.
RD’: This is used for read operation. It is an output signal. It is active when low.
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).
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.
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.
INTA : Interrupt acknowledge. It is active low(0) during T2, T3 and Tw of each interrupt acknowledge
cycle.
MN/MX’ : Minimum/Maximum. This pin signal indicates what mode the processor will operate in.
RQ’/GT1′, RQ’/GT0′ : Request/Grant. These pins are used by local bus masters used to force the
microprocessor to release the local bus at the end of the microprocessor’s current bus cycle. Each of the
pin is bi-directional. RQ’/GT0′ have higher priority than RQ’/GT1′.
LOCK’ : Its 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.
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.
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.
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.
Vcc : Power Supply( +5V D.C.)
GND : Ground
QS1,QS0 : Queue Status. These signals indicate the status of the internal 8086 instruction queue
according to the table shown below:
QS1 QS0 Status
0 0 No operation
M/IO’: This signal is used to distinguish between memory and I/O operations. The M Signal is Active
high whereas the IO’ Signal is Active Low. When this Pin is High, the memory operations takes place.
On the other hand, when the Pin is low, the Input/Output operations from the peripheral devices takes
place.
=DT/R : Data Transmit/Receive. This pin is required in minimum systems, that want to use an 8286 or
8287 data bus transceiver. The direction of data flow is controlled through the transceiver.
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.
HOLD/HOLDA: HOLD indicates that another master has been requesting a local bus .This is an
active high(1). The microprocessor receiving the HOLD request will issue HLDA (high) as an
acknowledgement in the middle of a T4 or T1 clock cycle.
ALE : Address Latch Enable. ALE is provided by the microprocessor to latch the address into the 8282
or 8283 address latch. It is an active high(1) pulse during T1 of any bus cycle. ALE signal is never
floated, is always integer.
The Flag register is a Special Purpose Register. Depending upon the value of result after any arithmetic and
logical operation the flag bits become set (1) or reset (0).
Figure – Format of flag register There are total 9 flags in 8086 and the flag register is divided into two
types: (a) Status Flags – There are 6 flag registers in 8086 microprocessor which become set(1) or reset(0)
depending upon condition after either 8-bit or 16-bit operation. These flags are conditional/status flags. 5 of
these flags are same as in case of 8085 microprocessor and their working is also same as in 8085
microprocessor. The sixth one is the overflow flag. The 6 status flags are:
1. Sign Flag (S)
2. Zero Flag (Z)
3. Auxiliary Carry Flag (AC)
4. Parity Flag (P)
5. Carry Flag (CY)
These first five flags are defined here
6. Overflow Flag (O) – This flag will be set (1) if the result of a signed operation is too large to fit in the
number of bits available to represent it, otherwise reset (0). After any operation, if D[6] generates any
carry and passes to D[7] OR if D[6] does not generates carry but D[7] generates, overflow flag becomes
set, i.e., 1. If D[6] and D[7] both generate carry or both do not generate any carry, then overflow flag
becomes reset, i.e., 0. Example: On adding bytes 100 + 50 (result is not in range -128…127), so overflow
flag will set.
MOV AL, 50 (50 is 01010000 which is positive)
MOV BL, 32 (32 is 00110010 which is positive)
ADD AL, BL (82 is 10000010 which is negative)
1. Overflow flag became set as we added 2 +ve numbers and we got a -ve number.
(b) Control Flags – The control flags enable or disable certain operations of the microprocessor. There are 3
control flags in 8086 microprocessor and these are:
1. Directional Flag (D) – This flag is specifically used in string instructions. If directional flag is set (1),
then access the string data from higher memory location towards lower memory location. If directional
flag is reset (0), then access the string data from lower memory location towards higher memory location.
2. Interrupt Flag (I) – This flag is for interrupts. If interrupt flag is set (1), the microprocessor will
recognize interrupt requests from the peripherals. If interrupt flag is reset (0), the microprocessor will not
recognize any interrupt requests and will ignore them.
3. Trap Flag (T) – This flag is used for on-chip debugging. Setting trap flag puts the microprocessor into
single step mode for debugging. In single stepping, the microprocessor executes a instruction and enters
into single step ISR. If trap flag is set (1), the CPU automatically generates an internal interrupt after each
instruction, allowing a program to be inspected as it executes instruction by instruction. If trap flag is
reset (0), no function is performed.
INTERRUPT: An interrupt is a condition that halts the microprocessor temporarily to work on a different task
and then returns to its previous task. An interrupt is an event or signal that requests the CPU’s attention. This
halt allows peripheral devices to access the microprocessor.
TYPES OF INTERRUPTS
Hardware Interrupts – Hardware interrupts are those interrupts that are caused by any peripheral device by
sending a signal through a specified pin to the microprocessor. There are two hardware interrupts in the 8086
microprocessor. They are:
NMI (Non-Maskable Interrupt): It is a single pin non-maskable hardware interrupt that cannot be
disabled. It is the highest priority interrupt in the 8086 microprocessor. After its execution, this
interrupt generates a TYPE 2 interrupt. IP is loaded from word location 00008 H, and CS is
loaded from the word location 0000A H.
INTR (Interrupt Request): It provides a single interrupt request and is activated by the I/O port.
This interrupt can be masked or delayed. It is a level-triggered interrupt. It can receive any
interrupt type, so the value of IP and CS will change on the interrupt type received.
2. Software Interrupts – These are instructions inserted within the program to generate interrupts. There
are 256 software interrupts in the 8086 microprocessor. The instructions are of the format INT type,
where the type ranges from 00 to FF. The starting address ranges from 00000 H to 003FF H. These are
2-byte instructions. IP is loaded from type * 04 H, and CS is loaded from the following address given by
(type * 04) + 02 H.
3. Predefined interrupts
INSTRUCTION SET
1. Logical instructions in 8086 microprocessor
Logical instructions are the instructions which perform basic logical operations such as AND, OR, etc. In 8086
microprocessor, the destination operand need not be the accumulator. Following is the table showing the list of
logical instructions:
OPCODE OPERAND DESTINATION EXAMPLE
OR D, S D = D OR S OR AX, BX
TEST [0250],
TEST D, S performs bit-wise AND operation and affects the flag register 06
RCR D, C rotates all bits in D to the right along with carry flag C times RCR BL, CL
RCL R, C rotates all bits in D to the left along with carry flag C times RCL BX, 06
Here D stands for destination, S stands for source and C stands for count. They can either be register, data or
memory address
2. Arithmetic instructions in 8086 microprocessor
Arithmetic Instructions are the instructions which perform basic arithmetic operations such as addition,
subtraction and a few more. Unlike in 8085 microprocessor, in 8086 microprocessor the destination operand
need not be the accumulator.
Following is the table showing the list of arithmetic instructions:
OPCODE OPERAND EXPLANATION EXAMPLE
PUSHA none put all the registers into the stack PUSHA
POPA none gets words from the stack to all registers POPA
LAHF none loads AH with the lower byte of the flag register LAHF
SAHF none stores AH register to lower byte of the flag register SAHF
PUSHF none copies the flag register at the top of the stack PUSHF
POPF none copies a word at the top of the stack to the flag register POPF
REP
REP instruction repeat the given instruction till CX != 0 MOVSB
MOVSB none moves contents of byte given by DS:SI into ES:DI MOVSB
MOVSW none moves contents of word given by DS:SI into ES:DI MOVSW
MOVD none moves contents of double word given by DS:SI into ES:DI MOVD
LODSB none moves the byte at address DS:SI into AL; SI is incr/decr by 1 LODSB
LODSW none moves the word at address DS: SI into AX; SI is incr/decr by 2 LODSW
SCASB none compares byte at ES:DI with AL and sets flags according to result SCASB
SCASW none compares word at ES:DI with AX and sets flags SCASW
SCASD none compares double word at ES:DI with EAX and sets flags SCASD
CMPSB none compares byte at ES:DI with byte at DS:SI and sets flags CMPSB
CMPSW none compares word at ES:DI with word at DS:SI and sets flags CMPSW
compares double word at ES:DI with double word at DS:SI and sets
CMPSD none flags CMPSD
Assembler directives
Assembler directives are the instructions used by the assembler at the time of assembling a
source program. More specifically, we can say, assembler directives are the commands or
instructions that control the operation of the assembler.
Assembler directives are the instructions provided to the assembler, not the processor as the
processor has nothing to do with these instructions. These instructions are also known
as pseudo-instructions or pseudo-opcode.
1. DB: Define Byte: The DB directive is used to reserve byte or bytes of memory locations in the available memory.
Example: VALUE DB 50H
LIST DB 0lH, 02H, 03H, 04H
• This statement directs the assembler to reserve four memory locations for a list named LIST and initialise them with the
above specified four values.
• MESSAGE DB 'GOOD MORNING'
Assembler directives
2. DW: Define Word: The DW directive serves the same purposes as the DB directive, but it now makes the assembler
reserve the number of memory words (16-bit) instead of bytes.
EX: WORDS DW 1234H
•Another option of the DW directive is explained with the DUP operator.
EX: WDATA DW 5 DUP (6666H)
• This statement reserves five words, i.e. 10-bytes of memory for a word lable WDATA and initializes all the word
locations with 6666H.
3.DQ: Define Quad word: This directive is used to direct the assembler to reserve 4 words (8 bytes) of memory for the
specified variable and may initialise it with the specified values.
4. DT: Define Ten Bytes: The DT directive directs the assembler to define the specified variable requiring la-bytes for its
storage and initialise the 10bytes with the specified values.
5. ASSUME: Assume Logical Segment Name The ASSUME directive is used to inform the assemble, the names of the
logical segments to be assumed for different segments used in the program.
6. END: END of Program The END directive marks the end of an assembly language program. END statement should
be the last statement in the file
7. SEGMENT: Logical Segment The SEGMENT directive marks the starting of a logical segment. The started segment
is also assigned a name, i.e. label, by this statement.
8. ENDS: END of Segment This directive marks the end of a logical segment. Any statement
appearing after ENDS will be neglected from the segment.
EX: DATA SEGMENT
.
.
.
DATA ENDS
ASSUME CS: CODE, DS:DATA
CODE SEGMENT.
.
.
.
CODE ENDS
END
The above structure represents a simple program containing two segments named DATA and CODE. The data related to
the program must lie between the DATA SEGMENT and DATA ENDS statements. Similarly, all the executable
instructions must lie between CODE SEGMENT and CODE ENDS statements.
9. EQU: Equate: The directive EQU is used to assign a label with a value or a symbol. The use of this directive is just to
reduce the recurrence of the numerical values or constants in a program code. The recurring value is assigned with a label,
and that label is used in place of that numerical value, throughout the program.
Example LABEL EQU 0500H
ADDITION EQU ADD
Syntax of macro :
%macro macro_name number_of_parameters
<macro body>
%endmacro
2. Procedure :
Procedures are also like macro, but they are used for large set of instruction when macro is useful for small
set of instructions. It contains a set of instructions which performs a specific task. It contains three main
parts i.e Procedure name to identify the procedure, procedure body which contains set of instructions, and
RET statement which denotes return statement. Unlike macros, procedures follow call-return method
thereby achieving true modularity.
Syntax of Procedure :
procedure_name :
procedure body ….......................
RET
To call a procedure
CALL procedure_name
After execution of procedure control passes to the calling procedure using RET statement.
It is used for small set of instructions mostly less It is used for large set of instructions mostly more
02. than ten instructions. than ten instructions.
03. In case of macro memory requirement is high. In case of procedure memory requirement is less.
CALL and RET instruction/statements are not CALL and RET instruction/statements are required
04. required in macro. in procedure.
Assembler directive MACRO is used to define Assembler directive PROC is used to define
macro and assembler directive ENDM is used to procedure and assembler directive ENDP is used to
05. indicate the body is over. indicate the body is over.
Execution time of macro is less as it executes faster Execution time of procedures is high as it executes
06. than procedure. slower than macro.
In a macro parameter is passed as part of statement In a procedure parameters are passed in registers
08. that calls macro. and memory locations of stack.
Overhead time does not take place as there is no Overhead time takes place during calling procedure
09. calling and returning. and returning control to calling program.
8086 STACK
The stack is a block of memory that may be used for temporarily storing the contents of
the registers inside the CPU. It is a top-down data structure whose elements are accessed using
the stack pointer (SP) which gets decremented by two as we store a data word into the stack and
gets incremented by two as we retrieve a data word from the stack back to the CPU register.
The process of storing the data in the stack is called ‘pushing into’ the stack and the
reverse process of transferring the data back from the stack to the CPU register is known as
‘popping off’ the stack. The stack is essentially Last-In-First-Out (LIFO) data segment. This
means that the data which is pushed into the stack last will be on top of stack and will be
popped off the stack first.
The stack pointer is a 16-bit register that contains the offset address of the memory
location in the stack segment. The stack segment, like any other segment, may have a memory
block of a maximum of 64 Kbytes locations, and thus may overlap with any other segments.
Stack Segment register (SS) contains the base address of the stack segment in the memory.
The Stack Segment register (SS) and Stack pointer register (SP) together address the stack-top
as explained below:
If the stack top points to a memory location 52050H, it means that the location 52050H is
already occupied with the previously pushed data. The next 16 bit push operation will
decrement the stack pointer by two, so that it will point to the new stack-top 5204EH and the
decremented contents of SP will be 204EH. This location will now be occupied by the recently
pushed data.
Thus for a selected value of SS, the maximum value of SP=FFFFH and the segment can have
maximum of 64K locations. If the SP starts with an initial value of FFFFH, it will be
decremented by two whenever a 16-bit data is pushed onto the stack. After successive push
operations, when the stack pointer contains 0000H, any attempt to further push the data to the
stack will result in stack overflow.
After a procedure is called using the CALL instruction, the IP is incremented to the next
instruction. Then the contents of IP, CS and flag register are pushed automatically to the stack.
The control is then transferred to the specified address in the CALL instruction i.e. starting
address of the procedure. Then the procedure is executed.
Push
• Pop
• Top of stack
• Stack pointer
• LIFO
STACK INSTRUCTIONS
The two set of instructions which explicitly modify the stack are the PUSH (which places items on the stack) and the POP (which
retrieves items from the stack). In both cases, the stack pointer is adjusted accordingly to point always to the top of stack.
Thus, PUSH AX means SP=SP-2 and AX -> [SP]
POP AX means [SP] -> AX and SP=SP+2.