Coa - 8086 Internal Architecture
Coa - 8086 Internal Architecture
Fig. 6.2 shows a block diagram of the 8086 internal architecture. It is internally
divided into two separate functional units. These are the Bus Interface Unit
(BIU) and the Execution Unit (EU). These two functional units can work
simultaneously to increase system speed and hence the throughput.
Throughput is a measure of number of instructions executed per unit time.
us Interface Unit:
The bus interface unit is the 8086 Internal Architecture to the outside world. It
provides a full 16-bit bi-directional data bus and 20-bit address bus. The bus
interface unit is responsible for performing all external bus operations, as listed
below.
Instruction Queue:
To speed up program execution, the BIU fetches six instruction bytes ahead
of time from the memory. These prefetched instruction bytes are held for the
execution unit in a group of registers called Queue. With the help of queue it is
possible to fetch next instruction when current instruction is in execution. For
example, current instruction in execution is a multiplication instruction. In 8086
Internal Architecture, operands for multiplication operations are within registers.
Still it requires 100 clock cycles to execute multiply instruction. Like
multiplication there are number of other instructions in 3086 which need a quite
a large number- of clock cycles for execution. During this execution time the
BIU fetches the next instruction or instructions from memory into the instruction
queue instead of remaining idle. The BIU continues this process as long as the
queue is not full. Due to this, execution unit gets the ready instruction in the
queue and instruction fetch time is eliminated. This is illustrated in Fig. 6.3.
The queue operates on the principle first in first out (FIFO). So that the
execution unit gets the instructions for execution in the order they are fetched.
In case of JUMP and CALL instructions, instruction already fetched in queue
are of no use. Hence, in these cases queue is dumped and newly formed by
loading instructions from new address specified by JUMP or CALL instruction.
Feature of fetching the next instruction while the current instruction is
executing is called pipelining.
Segment Registers:
The physical address of the 8086 Internal Architecture is 20-bits wide to access
1 Mbyte memory locations. However, its registers and memory locations which
contain logical addresses are just 16-bits wide. Hence 8086 uses memory
segmentation. It treats the 1 Mbyte of memory as divided into segments, with a
maximum size of a segment as 64 Kbytes. Thus any location within the segment
can be accessed using 16 bits. The 8086 Internal Architecture allows only four
active segments at a time, as shown in the Fig. 6.4. For the selection of the four
active segments the 16-bit segment registers are provided within the BIU of the
8086. These four registers are :
Code segment (CS) register, the data segment (DS) register, the stack segment
(SS) register, and the extra segment (ES) register. These are used to hold the
upper 16-bits of the starting addresses of the four memory segments, on which
8086 works at a particular time. For example, the value in CS identifies the
starting address of 64 K-byte segment known as code segment. By “starting
address“, we mean the lowest addressed byte in the active code segment. The
starting address is also known as base address or segment base.
The BIT) always inserts zeros for the lowest 4 bits (nibble) in the contents of
segment register to generate 20-bit base address. For example, if the code
segment register contains 348AH, then code segment will start at address
348A0H.
Instruction Pointer:
The instruction pointer register holds the 16-bit address of the next Code byte
within the code segment. The value contained in the IP is referred to as an
offset. This value must be offset from (added to) the segment base address in
CS to produce the required 20-bit physical address.
Flag Register:
A flag is a flip–flop which indicates some condition produced by the execution
of an instruction or controls certain operations of the EU. The flag register
contains nine active flags as shown in the Fig. 6.6.
General Purpose Registers:
The EU has. 8 general purpose registers labelled AH, AL, BH, BL, CH, CL, DH,
and DL. These registers can be used individually for temporary storage of 8 bit
data. The AL register is also called accumulator. Certain pairs of these general
purpose registers can be used together to store 16-bit data, such as AX, BX,
CX and DX.
These additional registers belong to the pointer and index group. The pointer
and index group consists of instruction pointer (IP), stack pointer (SP), BP (base
pointer), source index (SI) and destination index (DI) registers.
Stack Pointer (SP) : The stack pointer (SP) register contains the 16-bit offset
from the start of the segment to the top of stack. For stack operation, physical
address is produced by adding the contents of stack pointer register to the
segment base address in SS. To do this the contents of the stack segment
register are shifted four bits left and the contents of SP are added to the shifted
result. If the contents of SP are 9F20H and SS are 4000H then the physical
address is calculated as follows. (Refer Fig. 6.7)
Base pointer : We can use the BP register instead of SP for accessing the
stack using the based addressing. mode. In this case, the 20-bit physical stack
address. is calculated from BP and SS. Addressing modes are discussed in
later section.
Source Index : Source index (SI) can be used to hold the offset of a data word
in the data segment. In this case, the 20-bit physical data address is calculated
from SI and
Destination Index : The ES register .points to the extra segment in which data
is stored. String instructions always use ES and DI to determined the 20-bit
physical address for the destination.
2.S2,S1,S0 (output) : These three status signals indicate the type of transfer to
be take place during the current bus cycle.
3.LOCK : This signal indicates that an instruction with a LOCK prefix is being
executed and the bus is not to be used by another processor:
Fig. 10.9 shows that the 8288 is able to originate the address latch enable
signal to the 8282’s, the enable and direction signals to the 8286 transceivers,
and the interrupt acknowledge signal to the interrupt controller. It also decodes
the S2-S0 signals to generate MRDC, MWTC, IORC, IOWC, MCE/PDEN, AEN,
IOB, CEN, AIOWC, and AMWC signals.
MRDC (Memory Read Command) : It instructs the memory to put the contents
of the addressed location on the data bus.
MWTC (Memory Write Command) : It instructs the memory to accept the data
on the data bus and load the data into the addressed memory location.
IORC (I/O Read Command) : It instructs an I/O device to put the data contained
in the addressed port on the data bus.
IOWC (I/0 Write Command) : It instructs an I/O device to accept the data on
the data bus and load the data into the addressed port.
Together BHE and A0 tell the interface how the data appears on bus. Four
possible combinations are shown in the Table 10.2.
Note : To access odd addressed word two bus cycles are required.
Every microprocessor based system has a memory system. Almost all systems
contain two basic types of memory, read-only memory (ROM) and random
access memory (RAM) or read/write memory. Read only memory contains
system software and permanent system data such as lookup tables, while
Random Access Memory contains temporary data and application software.
ROMs / PROMs / EPROMs are mapped to cover the CPU’s reset address,
since these are non-volatile. When the 8086 is reset; the next instruction is
fetched from memory location FFFF0H. So in the 8086 systems, the location
FFFF0H must be ROM location.
DEN (Data Enable) output : This signal informs the transceivers that the CPU
is ready to send or receive data.
DT/R (Data transmit/Receive) output : This signal is used to control data flow
direction. High on this pin indicates that the 8086 is transmitting the data and
low indicates that the 8086 is receiving the data.
M/IO output : It is used to distinguish memory data transfer, (M/I0 = HIGH) and
I/O data transfer (M/I0 = LOW).
WR : Write output : WR is low whenever the 8086 is writing data into memory
or an I/O device.
HOLD input, HLDA output : A HIGH on HOLD pin indicates that another
master (DMA) is requesting to take over the system bus. On receiving HOLD
signal processor outputs HLDA signal HIGH as an acknowledgment. At the
same time, processor tristates the system bus. A low on HOLD gives the system
bus control back to the processor. Processor then outputs low signal on HLDA.
DT/R signal is connected to the T input, which controls the direction of the data
flow. When this signal is low, receivers are enabled, so that 8086 can read data
from memory or input device. To write data into memory or output device, the
8086’s DT/R signal goes high. Due to this drivers are enabled to transfer data
from 8086 to the memory or the output device. At the time of data transfer, to
enable output of transceiver its OE should be low. This is accomplished by
connecting DEN signal of 8086 to the OE pin of 8286, since DEN signal goes
low when CPU is ready to send or receive data.
The third component. other than the processor that appears in Fig. 10.2 is an
8284 clock generator. The 8284 clock generator does the following functions
• Clock generation
• RESET synchronization
• READY synchronization
• Peripheral clock generation.
The Fig. 10.5 shows the internal logic diagram of 8284.
The top half of the logic diagram represents the clock and reset synchronization
section of the 8284 clock generator. As shown in the logic diagram, the crystal
oscillator has two inputs : X1 and X2. If a crystal is attached to X1 and X2, the
oscillator generates a square-wave signal at the same frequency as the crystal.
The output of oscillator is fed to an AND gate and also to an inverter buffer that
provides the osc output signal. The F/C signal selects one of the oscillator
inputs. When F/C input is 1, the EFI input determines the frequency; otherwise
oscillator determines the frequency. When EFI input is used, CSYNC signal is
used for multiple buffered before it leaves the clock generator. As shown in the
Fig. 10.5, the output of the divide-by-3 counter generates the timing for ready
synchronization, a signal for another counter (divide-by-2), and the CLK signal
to the 8086/8088 microprocessors. The two cascaded counters (divide-by-3
and divide-by-2) provide the divide-by-6 output at PCLK, which can be used to
provide clock input for peripherals. The address enable pins, AEN1 and AEN2
are provided to qualify the bus ready signals, RDY1 and RDY2, respectively.
The reset circuit of 8284 consists of a schmitt trigger buffer and a single D flip-
flop circuit. The D flip-flop ensures that the timing requirements of the
8086/8088 RESET input are met. 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/8088.
The Fig. 10.6 shows the circuit connection for 8284 clock generator. The 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 register. A push button switch
allows the microprocessor to be reset by the operator.
The status on the M/IO, RD, and WR lines decides the type of data transfer, as
listed in the Table 10.1.
HOLD and HLDA signals are used to interface other bus masters like DMA
controller. Interrupt request (INTR) and interrupt acknowledge (INTA) are used
to extend the interrupt handling capacity of the 8086 with the help of interrupt
controller.
2.A19/S6-A16/S3 : During the first part of machine cycle these are used to output
upper 4-bits of address. During remaining part of the machine cycle these are
used to output status, which indicates the type of operation to be performed in
that cycle. S3 and S4 indicate the segment register being used as follows :
S5 gives the current setting of the interrupt flag (IF) and S6 is always zero.
3.BHE/S7 : BHE (Bus High Enable) : Low on this pin during first part of the
machine cycle, indicates that at least one byte of the current transfer is to be
made on higher order byte AD15-AD8; otherwise the transfer is made on lower
order byte AD7-AD0.
Status S7 is output during the later part of the machine cycle, but, presently, 5 7
has not been assigned a meaning.
6.CLK : 8086 requires clock signal (with 33 % duty cycle) from some external,
crystal controlled generator to synchronize internal operations. Clock frequency
depends
7.RESET : It clears PSW, IP, DS, SS, ES, and the instruction queue. It then
sets CS to FITIMI. This signal must be high for at least 4 clock cycles. When
RESET is removed, 8086 will fetch its next instruction from physical address
FEFFOH.
8.READY : If this signal is low the 8086 enters into wait state. This signal is
used primarily to synchronize slower peripherals with the microprocessor.
9.TEST (Input) : This signal is only used by the WAIT instruction. The 8086
enters into a wait state after execution of the WAIT instruction until a LOW signal
on the TEST pin. TEST signal is synchronized internally during each clock cycle
on the leading edge of the clock cycle.
10.RD (Output) : RD is low whenever the 8086 is reading data from memory or
an I/O device.
11. MN/MX (Input) : The 8086 can be configured in either minimum mode or
maximum mode using this pin. This pin is tied high for minimum mode.
These instructions add a number from source to a number from destination and
put the result in the destination. The ADC, instruction also adds the status of
carry flag into the result. The source may be an immediate number, a register,
or a memory location. The source and the destination in an instruction cannot
both be memory locations. The source and destination both must be a word or
byte. 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 zeroes before adding.
The INC instruction adds 1 to the specified destination. The destination may be
a register or memory location. The AF, OF, PF, SF and ZF flags are affected.
The numbers from 0-9 are represented as 30H-39H in ASCII code. When you
want to add two decimal digits which are represented in ASCII code, it is
necessary to mask upper nibble (3) from the code before addition. The 8086
Arithmetic Instructions allows you to add the ASCII codes for two decimal digits
without masking off the “3” in the upper nibble of each digit. The AAA instruction
can be used after addition to get the current result in unpacked BCD form.
This instruction is used to make sure the result of adding two packed BCD
numbers is adjusted to be a legal BCD number.
These instructions subtract the number in the source from the number in the
desfinafion and put result in the desfinafion. The SBB, instruction also subtracts
the status of carry flag from the result. The source may be an immediate
number, a register, or a memory location. The destination maybe a register or
a memory location. The source and the desfinafion both cannot be memory
locafions. The source and destination both mustbeword or byte. If you want to
subtract a byte from a word, you must copy the byte to a word location and fill
the upper byte of the word with zeroes before subtracting.
The DEC instruction subtract 1 from the specified destination. The destination
may be a register or a memory location. The AF, OF, PF, SF and ZF flags are
affected.
This, instruction replaces the number in a destination with the 2’s complement
of that number. The destination can be a register or a memory location. This
instruction can be implemented by inverting each bit and adding 1 to it
The negate instruction updates the AF, CF, SF, PF, ZF and OF flags.
Flags : The AF, OF, SF, ZF, PF and CF are updated by the CMP instruction.
The numbers from 0-9 are represented as 30-39 in ASCII code. When you want
to subtract two decimal digits which are represented in ASCII code, it is
necessary to mask upper nibble (3) from the code before subtraction. The 8086
Arithmetic Instructions allows you to subtract the ASCII codes for two decimal
digits without masking off the “3” in the upper nibble of each digit. The AAS
instruction can be .used after subtraction to get the current result in unpacked
BCD form.
This instruction is used after subtracting two packed BCD numbers to make
sure the result is correct packed BCD. Instruction works as follows :
1. If the value of the low-order four bits (D3-D0) in the AL is greater than 9 o AF is set; the
instruction subtracts 6 (06) from the low-order four bits.
2. If the value of the high-order four bits (D7-D4) in the AL is greater than 9 or if carry flag is
set, the instruction subtracts 6 (60) from the high-order four bits.
c) Multiplication Instructions:
• MUL
• IMUL
• AAM
MUL Instruction : MUL source.
This instruction multiplies an unsigned byte from source and unsigned byte in
AL register or unsigned word from source and unsigned word in AX register.
The source can be a register or a memory location. When the byte is multiplied
by the contents of AL, the result is stored in AX. The most significant byte is
stored in AH and least significant byte is stored in AL. When a word is multiplied
by the contents of AX, the most significant word of result is stored in DX and
least significant word of result is stored in AX.
IMUL Instruction :
This instruction multiplies a signed byte from some source and a signed byte in
AL, or a signed word from some source and a signed word in AX. The source
can be register or memory location. When a signed byte is multiplied by AL a
signed result will be put in AX. When a signed word is multiplied by AX, the
high-order word of the signed result is put in DX and the low-order word of the
signed result is put in AX.
If the upper byte of a 16-bit result or the upper word of 32-bit result contains
only copies of the sign bit (all 0’s or all 1’s), then the CF and the OF flags will
both be 0’s. The AF, PF, SF, and ZF flags are undefined after IMUL.
To multiply a signed byte by a signed word it is necessary to move the byte into
a word location and fill the upper byte of the word with copies of the sign bit.
This can be done using CBW instruction.
After the two unpacked BCD digits are multiplied, the AAM instruction is used
to adjust the product to two unpacked BCD digits in AX.
d) Division Instructions:
• DIV
• IDIV
• AAD
DIV Instruction : DIV source
When dividing a word by a byte, the word must be in AX register. After the
division AL will contain an 8-bit quotient and AH will contain an 8-bit remainder.
If an attempt is made to divide by 0 or the quotient is too large to fit in AL (greater
than FFH), the 8086 Arithmetic Instructions will automatically execute a type 0
interrupt.
When a double word is divided by a word, the most significant word of the
double word must be in DX and the least-significant word must be in AX. After
the division AX will contain a 16-bit quotient and DX will contain a 16-bit
remainder. Again, if an attempt is made to divide by 0 or the quotient is too large
to fit in AX register (greater than FFFFH), the 8086 Arithmetic Instructions will
do a type 0 interrupt. For DIV instruction source may be a register or memory
location.
To divide a byte by a byte, it is necessary to put the dividend byte in AL and fill
AH with all 0’s. Similarly, to divide a word by a word, it is necessary to put the
dividend word in AX and fill DX with all 0’s.
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 division AL will contain
the unpacked BCD quotient and AH will contain the unpacked BCD remainder.
The PF, SF and ZF are updated. The AF, CF and OF are undefined after AAD.
This instruction copies the sign of a byte in AL to all the bits in AH. AH is then
said to be sign extension of AL.
This instruction copies the sign bit of a word in AX to all the bits of the DX
register. DX is then said to be sign extension of AX.
This instruction logically ANDs each bit of the source byte or word with the
corresponding bit in the destination and stores result in the destination. 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 destination
both cannot be memory locations in the same instruction. The CF and OF are
both 0 after AND. The PF, SF and ZF are affected. AF is undefined.
This instruction logically ORs each bit of the source byte or word with the
corresponding bit in the destination and stores result in the destination. 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 destination
both can not be memory locations in the same instruction. The CF and OF are
both 0 after OR. The PF, SF and ZF are affected. AF is undefined.
XOR Instruction : XOR destination, source.
This instruction logically XORs each bit of the source byte or word with the
corresponding bit in the destination and stores result in the destination. 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 destination
both cannot be memory locations in the same instruction. The CF and OF are
both 0 after XOR. The PF, SF and ZF are affected. AF is undefined.
This 8086 Bit Manipulation Instructions ANDs the contents of a source byte or
word with the contents of the specified destination word. Flags are affected. But
neither operand is changed. PF, SF and ZF will be updated to show the results
of the ANDing. PF has meaning only for the lower 8 bits of the destination. AF
will be undefined.
The PUSH instruction decrements stack pointer by two and copies a word from
some source to the location in the stack where the stack pointer points. Here
the source must be a word (16 bit). The source of the word can be a general
purpose register, a segment register or memory.
The POP instruction copies a word from the stack location pointed by the stack
pointer to the destination. The destination can be a general purpose register, a
segment register, or a memory location. After the word is copied to the specified
destination, the stack pointer is automatically incremented by 2.
The XCHG instruction exchanges the contents of a register with the contents of
another register or the contents of a register with the contents of a memory
location(s). The instruction cannot exchange the contents of two memory
locations. The source and destination both must be words or bytes. The
segment registers can’t be used in these instructions.
The XLAT instruction replaces a byte in the AL register with a byte from a lookup
table in memory. BX register stores the offset of the starting address of the
lookup table and AL register stores the byte number from the lookup table. This
instruction –copies byte from address pointed by [BX + AL] back into. AL.
This instruction determines the offset of the variable or memory location named
as the source and loads this address in the specified 16-bit register. Flags are
not affected by LEA instruction.
LDS Instruction : Load register and DS with words from memory. LDS register,
memory address of first word.
This instruction copies a word from two memory locations into the register
specified in the instruction. It then copies a word from the next two memory
locations into the DS register.
LES Instruction : Load register and ES with words from memory. LES register,
memory address of first word.
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 location is copied into the specified register and the word from the next
two memory locations is copied into the ES register.
This instruction copies the contents of lower byte of 8086 Data Transfer
Instructions flag register to AH register.
The contents of the AH register are copied into the lower byte of the 8086 Data
Transfer Instructions flag register.
This instruction decrements the stack pointer by 2 and copies the word in the
flag register to the memory location(s) pointed by the stack pointer.
This instruction copies a word from the two memory locations at the top of stack
to the flag register and increments ‘stack pointer by 2.
The OUT instruction copies a byte from AL or a word from AX to the specified
port.
The HLT instruction will cause the 8086 to stop fetching and executing
instructions. The 8086 will enter a halt state. The only 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.
WAIT Instruction :
When this instruction executes, the 8086 enters an idle condition where it is
doing no processing. The 8086 will stay in this idle state until a signal is asserted
on the 8086 TEST input pin, or until a valid interrupt signal is received on the
INTR or the NMI interrupt input pins. If a valid interrupt occurs while the 8086 is
in this idle state, the 8086 will return to the idle state after the execution of
interrupt service procedure. WAIT affects, no flags. The WAIT, instruction is
used to synchronize the 8086 with 8086 External Hardware Synchronization
Instructions such as the 8087 math coprocessor.
ESC Instruction :
LOCK Instruction :
In a multiprocessor system each microprocessor has its own local’ buses and
memory. The individual microprocessors are connected together by a system
bus so that each can access system resources such as disk drives , or, memory.
Each microprocessor only takes control of the system bus when it needs to
access some system resources. The LOCK prefix allows a microprocessor to
make sure that another processor does not take control of the system bus while
it is in the middle of a critical instruction which uses the system bus. The LOCK
prefix is put in front of the critical instruction. When an instruction with a LOCK
prefix executes, the 8086 will assert its bus lock signal output. This signal is
connected to an 8086 External Hardware Synchronization Instructions bus
controller device which then prevents any other processor from taking over the
system bus. LOCK affects no flags.
NOP Instruction :
This instruction sets the carry flag, STC does not affect any other flag.
CLC Instruction :
This instruction resets the carry flag to zero. CLC does not affect any other flag.
CMC Instruction :
This instruction complements the carry flag. CMC does not affect any other flag.
STD Instruction :
This instruction is used to set the direction flag to one so that SI and/or DI can
be decremented automatically after execution of string instructions. STD does
not affect any other flags,
CLD Instruction :
This instruction is used to reset the direction flag to zero, so that SI and/or DI
can be incremented automatically after execution of string instructions. CLD
does not affect any other flag.
STI Instruction :
This 8086 Processor Control Instruction sets the interrupt flag to one. This
enables INTR interrupt of the 8086. STI does not affect any other flag.
CLI Instruction :
This instruction resets the interrupt flag to zero. Due to this 8086 Processor
Control Instruction will not respond to an interrupt signal on its INTR input. CLI
does not affect any other flag.
This instruction causes the 8086 to call a far procedure. The term type in the
instruction refers to a number between 0-255 which identifies the interrupt. The
address of the procedure is taken from the memory whose address is four times
the type number.
INTO Instruction :
If the overflow flag is set, this instruction will cause the 8086 to do an indirect
far call to a procedure you write to handle overflow condition. To do call the
8086 will read a new value for IP from address 00010H and a new value of CS
from address 00012H.
IRET Instruction :
The IRET instruction is used at the end of the interrupt service routine to return
execution to the interrupted program. The 8086 copies return address from
stack into IP and CS registers and the stored value of flags back to the flag
register.
Note : The RET instruction does not copy the flags from the stack back to the
flag register.
RET Instruction :
The RET instruction will return 8086 Program Execution Transfer Instructions
from a procedure to the next instruction after. the CALL instruction in the calling
program. If the procedure is a near procedure (in the same code segment as
the CALL instruction), then the return will be done by replacing the instruction
pointer with a word from the top of the stack.
If the procedure is a far procedure (in a different code segment from the CALL
instruction which calls it), then the instruction pointer will be replaced by the
word at the top of the stack. The stack pointer will then be incremented by two.
The code segment register is then replaced with a word from the new top of the
stack. After the code segment word is popped off the stack, the stack pointer is
again incremented by two. These words/word are the offset of the next
instruction after the CALL. So 8086 will fetch the next instruction after the CALL.
JMP Instruction :
This instruction will always cause the 8086 Program Execution Transfer
Instructions to fetch its next instruction from the location specified in the
instruction rather than from the next location after the JMP instruction.
There are two basic types of JMPs, near and far. A near JMP is a jump where
destination location is in the same code segment. In this case only IP is
changed. A near JMP is known as intrasegment JMP. A far JMP is a jump where
destination location is from a different segment. In this case both IP and CS are
changed as specified in the destination. A far IMP is known as Inter segment
JMP
Near and far jumps are further described as either direct or indirect. If the
destination address for the jump is specified directly within the instruction, then
the jump is described as direct. If the destination address for the jump is
contained in a register or memory location, the jump is referred as indirect,
because the 8086 has to access the specified register or memory location to
get the required destination address.
As explained earlier, a near type jump instruction can cause the next instruction
to be fetched from anywhere in the current code segment. To produce the new
instruction fetch address, this instruction adds a 16-bit signed displacement
contained in the instruction to the contents of the instruction pointer register. A
16 bit signed displacement means that the jump can be to a location anywhere
from +32,767 to -32,768 bytes from the current instruction pointer location. A
positive displacement usually means jump is ” ahead ” in the program, and a
negative displacement usually means jump is ” backward ” in the program.
A special case of the direct near jump instruction is direct short jump. If the
destination for the jump is within a displacement range of +127 to -128 bytes
from the current instruction pointer location, the destination can be reached with
just an 8 bit displacement.
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 iteration control
instruction. For LOOPE/LOOPZ and LOOPNE/LOOPNZ instructions there is
one more condition for exit from loop, which is given below. If the loop is not
taken, execution simply goes on to the next instruction after the iteration control
instruction.
This 8086 Rotate Instructions all bits in a specified byte or word to the left some
number of bit positions. MSB is placed as a new LSB and a new CF.
This 8086 Rotate Instructions all bits in a specified byte or word to the left some
number of bit positions. LSB is placed as a new MSB and a new CF.
This 8086 Rotate Instructions all of the bits in a specified word or byte some
number of bit positions to the left along with the carry flag. MSB is placed as a
new carry and previous carry is placed as a new LSB.
This 8086 Rotate Instructions all of the bits in a specified word or byte some
number of bit positions to the left along with the carry flag. LSB is placed as a
new carry and previous carry is placed as a new MSB.
SAL and SHL are two mnemonics for the same instruction. This instruction
shifts each bit in the specified destination to the left and 0 is stored at LSB
position. The MSB is shifted into the carry flag. The destination can be a byte
or a word. It can be in a register or in a memory location. The number of shifts
are indicated by count. But if the number of shifts required is one, you can place
1 in the count position. If number of shifts are greater than 1 then shift count
must be loaded in CL register and CL must be placed in the count position of
the instruction.
This 8086 Shift Instructions each bit in the specified destination to the right and
0 is stored at MSB position. The LSB is shifted into the carry flag. The
destination can be a byte or a word. It can be in a register or in a memory
location. The number of shifts are indicated by count. If number of shifts
required is one, you can place 1 in the count position. But if the number of shifts
are greater than 1 then shift count must be loaded in CL register and CL must
be placed in the count position of the instruction.
This 8086 Shift Instructions 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. The LSB will be shifted into CF. In the
case of multiple shifts, CF will contain the bit most recently shifted in from the
LSB. Bits shifted into CF previously will be lost.
REP is a prefix which is written before one of the 8086 String Instructions. These
instructions repeat until specified condition exists.
MOVS/MOVSB/MOVSW Instruction :
This instruction copies a byte or word from a location in the data segment to a
location in the extra segment. The offset of the source byte or word in the data
segment must be in the SI register. The offset of the destination in the extra
segment must be contained 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 word is moved SI and DI are
automatically adjusted to point to the next source and the next destination. If
the direction flag is 0, then SI and DI will be incremented by 1 after a byte move
and they will incremented by 2 after a word move. If the DF is a 1, then SI and
DI will be decremented by 1 after a byte move and they will be decremented by
2 after a word move. MOVS affects no flags.
The way to tell the assembler whether to code the instruction for a byte or word
move is to add a “B” or a “W” to the MOVS mnemonic. MOVSB, for example,
says move a string as bytes. MOVSW says move a string as words.
After move SI will be one greater than offset of last byte in source string. DI will
be one greater than offset of last byte of destination string. CX will be 0.
CMPS/CMPSB/CMPSW Instruction :
SCAS/SCASB/SCASW Instruction :
SCAS compares a string byte with a byte in AL or a string word with word in AX.
The instruction affects the flags, but it does not change either the operand in AL
(AX) or the operand in the 8086 String Instructions. The string to be ‘scanned
must be in the extra segment and DI must contain the offset of the byte or the
word to be compared.
LODS/LODSB/LODSW Instruction :
STOS/STOSB/STOSW Instruction :
In the maximum mode, the statics lines S0 to S2 enable the INTA output for
each cycle via the 8288. The 8086 activates LOCK froth T2 of the first cycle until
T2 of the second to prevent the 8086 from accepting a hold request on either
RQ/GT inputs and to prevent bus arbitration logic from releasing the bus
between INTAs in multiprocessor system.
8086 Interrupt Types:
The 8086 Interrupt Types are
Dedicated Interrupts:
Type 0 : Divide by Zero Interrupt
When the quotient from either a DIV or IDIV instruction is too large to fit in the
result register; 8086 Interrupt Types will automatically execute type 0 interrupt.
An 8086 Interrupt Types system is used in the single step mode by setting the
trap flag. If the trap flag is set, the 8086 will automatically execute a type 1
interrupt after execution of each instruction. But the 8086 has no such
instruction to directly set or reset the trap flag. These operations can be
performed by taking the flag register contents into memory, changing the
memory contents so to set or reset trap flag and save the memory contents into
flag register.
OR [ BP + 0 ], 0100H ; set the Bit 8 in the memory pointed by BP i.e. set TF bit
To reset the trap flag we have to reset Bit 8. This can be done by using AND
[BP + 0 ], OFEFFH instruction instead of OR [BP + 0], 0100H.
For example, if you add the 8-bit signed number 0111 1000 (+ 120 decimal) and
the 8 bit signed number 0110 1010 (t 106 decimal), result is 1110 0010 (- 98
decimal). In signed numbers, MSB (Most significant Bit) is reserved for sign and
other bits represent magnitude of the number. In the previous example, after
addition of two 8-bit signed numbers result is negative, since it is too large to fit
in 7 bits. To detect this condition in the program, you can put interrupt on
overflow instruction, INTO, immediately after the arithmetic instruction in the
program. If the overflow flag is not set when the 8086 executes the INTO
instruction, the instruction will simply function as an NOP (no operation).
However, if the overflow flag is set, indicating an overflow error, the 8086 will
execute a type 4 interrupt after executing the INTO instruction.
Software Interrupts:
Type 0 – 255 :
The 8086 INT instruction can be used to cause the 8086 to do one of the 256
possible interrupt types. The interrupt type is specified by the number as a part
of the instruction. You can use an INT2 instruction to send execution to an NMI
interrupt service routine. This allows you to test the NMI routine without needing
to apply an external signal to the NMI input of the 8086 Interrupt Types.
With the software interrupts you can call the desired routines from many
different programs in a system. e.g. BIOS in IBM PC. The IBM PC has in its
ROM collection of routines, each performing some specific function such as
reading character from keyboard, writing character to CRT. This collection of
routines referred to as Basic Input Output System or BIOS.
The BIOS routines are called with INT instructions. We will summarize interrupt
response and how it is serviced by going through following steps.
1. 8086 pushes the flag register on the stack.
2. It disables the single step and the INTR input by clearing the trap flag and interrupt
flag in the flag register.
3. It saves the current CS and IP register contents by pushing them on the stack.
4. It does an indirect far jump to the start of the routine by loading the new values of CS
and IP register from the memory whose address calculated by multiplying 4 to the
interrupt type. e.g. If interrupt type is 4 then memory address is 4 x 4 = 1010 = 10H. So
8086 Interrupt Types will read new value of IP from 00010H and CS from 00012H.
5. Once these values are loaded in the CS and IP, 8086 will fetch the instruction from
the new address which is the starting address of interrupt service routine.
6. An IRET instruction at the end of the interrupt service routine gets the previous
values of CS and IP by popping the CS and IP from the stack.
7. At the end the flag register contents are copied back into flag register by popping the
flag register form stack.
8086 Interrupt:
An 8086 interrupt can come from any one the three sources :
• External signal
• Special Instruction in the program
• Condition produced by instruction
External Signal (Hardware Interrupt):
An 8086 can get interrupt from an external signal applied to the nonmaskable
interrupt (NMI) input pin; or the interrupt (INTR) input pin.
Special Instruction:
8086 supports a special instruction, INT to execute special program. At the end
of the interrupt service routine, execution is usually returned to the interrupted
program.
At the end of each instruction cycle 8086 Interrupts checks to see if there is any
interrupt request. If so, 8086 responds to the interrupt by performing series of
actions (Refer Fig. 9.1).
1. It decrements stack pointer by 2 and pushes the flag register on the stack..
2. It disables the INTR interrupt input by clearing the interrupt flag in the flag
3. It resets the trap flag in the flag register.
4. It decrements stack pointer by 2 and pushes the current code segment register
contents on the stack.
5. It decrements stack pointer by 2 and pushes the current instruction pointer contents
on the stack.
6. It does an indirect far jump at the start of the procedure by loading the CS and IP
values for the start of the interrupt service routine (ISR).
An IRET instruction at the end of the interrupt service procedure returns
execution to the main program.
Now the question is “How to get the values of CS and IP register ?” The 8086
gets the new values of CS and IP register from four memory addresses. When
it responds to an interrupt, the 8686 goes to memory locations to get the CS
and IP values for the start of the interrupt service routine. In an 8086 Interrupt
system the first 1 Kbyte of memory from 00000H to 003FFH is reserved for
storing the starting addresses of interrupt service routines. This block of
memory is often called the interrupt vector table or the interrupt pointer
table. Since 4 bytes are required to store the CS and IP values for each interrupt
service procedure, the table can hold the starting addresses for 256 interrupt
service routines. Fig. 9.2 shows how the 256 interrupt pointers are arranged in
the memory table.
Each interrupt type is given a number between 0 to 255 and the address of each
interrupt js found by multiplying the type by 4 e.g. for type 11, interrupt address
is 11 x 4 = 4410= 0002CH
Only first five types have explicit definitions such as divide by zero and non
maskable interrupt. The next 27 interrupt types, from 5 to 31, are reserved by
Intel for use in future microprocessors. The upper 224 interrupt types, from 32
to 255, are available for user for hardware or software interrupts.
• External signal
• Special Instruction in the program
• Condition produced by instruction
External Signal (Hardware Interrupt):
An 8086 can get interrupt from an external signal applied to the nonmaskable
interrupt (NMI) input pin; or the interrupt (INTR) input pin.
Special Instruction:
8086 supports a special instruction, INT to execute special program. At the end
of the interrupt service routine, execution is usually returned to the interrupted
program.
At the end of each instruction cycle 8086 Interrupts checks to see if there is any
interrupt request. If so, 8086 responds to the interrupt by performing series of
actions (Refer Fig. 9.1).
1. It decrements stack pointer by 2 and pushes the flag register on the stack..
2. It disables the INTR interrupt input by clearing the interrupt flag in the flag
3. It resets the trap flag in the flag register.
4. It decrements stack pointer by 2 and pushes the current code segment register
contents on the stack.
5. It decrements stack pointer by 2 and pushes the current instruction pointer contents
on the stack.
6. It does an indirect far jump at the start of the procedure by loading the CS and IP
values for the start of the interrupt service routine (ISR).
An IRET instruction at the end of the interrupt service procedure returns
execution to the main program.
Now the question is “How to get the values of CS and IP register ?” The 8086
gets the new values of CS and IP register from four memory addresses. When
it responds to an interrupt, the 8686 goes to memory locations to get the CS
and IP values for the start of the interrupt service routine. In an 8086 Interrupt
system the first 1 Kbyte of memory from 00000H to 003FFH is reserved for
storing the starting addresses of interrupt service routines. This block of
memory is often called the interrupt vector table or the interrupt pointer
table. Since 4 bytes are required to store the CS and IP values for each interrupt
service procedure, the table can hold the starting addresses for 256 interrupt
service routines. Fig. 9.2 shows how the 256 interrupt pointers are arranged in
the memory table.
Each interrupt type is given a number between 0 to 255 and the address of each
interrupt js found by multiplying the type by 4 e.g. for type 11, interrupt address
is 11 x 4 = 4410= 0002CH
Only first five types have explicit definitions such as divide by zero and non
maskable interrupt. The next 27 interrupt types, from 5 to 31, are reserved by
Intel for use in future microprocessors. The upper 224 interrupt types, from 32
to 255, are available for user for hardware or software interrupts.
The assembly text is usually divided into fields, separated by spaces and tabs.
A format for a typical line from assembly language program can be given as
The first field, which is optional, is the label field, used to specify symbolic labels.
A label is an identifier that is assigned to the address of the first byte of the
instruction in which it appears. As mentioned earlier, the presence of a label is
optional, but if present, the label provides a symbolic name that can be used in
branch instructions to branch to the instruction.
The third and following fields are operands. The presence of the operands
depends on the instruction. Some instructions have no operands, some have
one, and some have two. If there are two operands, they are separated by a
comma.
The last field is a comment field. It begins with a delimiter such as the semicolon
and continues to the end of the line. The comments are for our benefits, they
tell us what the program is trying to accomplish. Fig. 8.2 shows a typical 8086
assembly language instruction.
As shown above every .IF directive must have a matching ENDIF to terminate
a tested condition. ELSE is optional. It provides an alternate action. The
assembly also allows to use relational operators with .IF statement.
REPEAT Statement
In macro the REPEAT statement is used to repeat macro sequence for a fix
number of time. The repetition count is specified immediately after the REPEAT
statement as shown in the program. The program shows a macro definition
which sends 26 ASCII characters from A through Z to the video screen. The
statements within the REPEAT and the first ENDM are repeated 26 times. It is
important to note that this macro has two ENDM statements. The first
represents end of REPEAT and second represents end of MACRO.
WHILE Statement
In macro, the WHILE statement is used to repeat macro sequence until the
expression specified with it is true. Like REPEAT, end of loop is specified by
ENDM statement. The WHILE statement allows to use relational operators in
its expression. The Table 8.6 shows the relational operators used with WHILE
statements.
FOR Statement
A FOR statement in the macro repeats the macro sequence for a list of data.
For example, if we pass two arguments to the macro then in the first iteration
the FOR statement gives the macro sequence using first argument and in the
second iteration it gives the macro sequence using second argument. Like
WHILE statement, end of FOR is indicated by ENDM statement. The program
shows the use of FOR statement in the macro.
Macros in Microprocessor:
Macro is a group of instructions. The Macros in Microprocessor assembler
generates the code in the program each time where the macro is ‘called’.
Macros can be defined by MACRO and ENDM assembler directives. Creating
macro is very similar to creating a new opcode that can be used in the program.
Do not confuse with .LIB files. Here, PUBIC and EXTRN diiectives are not
required.
Macros in Microprocessor:
Macro is a group of instructions. The Macros in Microprocessor assembler
generates the code in the program each time where the macro is ‘called’.
Macros can be defined by MACRO and ENDM assembler directives. Creating
macro is very similar to creating a new opcode that can be used in the program.
Do not confuse with .LIB files. Here, PUBIC and EXTRN diiectives are not
required.
1.Assembling Process:
As mentioned earlier, assembler translates a source file that was created using
the editor into machine language such as binary or object code. The assembler
reads the source file of our program from the disk where we saved it after
editing. An assembler usually reads our source file more than once.
The assembler generates two files on the floppy or hard during these two
passes. The first file is called the object file. The object file contains the binary
codes for the instructions and information about the addresses of the
instructions. The second file generated by the assembler is called assembler
list file. This file contains the assembly language statements, the binary code
for each instruction, and the offset for each instruction.
2.Linking Process:
A linker is a program used to join together several object files into one large
object file. When writing large programs, it is usually much more efficient to
divide the large program into smaller modules. Each Modular Programming can
be individually written, tested and debugged. When all the Modular
Programming work, they can be linked together to form a large functioning
program.
The linker produces a link file which contains the binary codes for all the
combined modules. The linker also produces a link map which contains the
address information about the link files. The linker, however, does not assign
absolute addresses to the program, it only assigns relative addresses starting
from zero. This form of the program is said to be relocatable, because it can be
put anywhere in memory to be run.
3.Debugging Process:
A debugger is a program which allows us to load our object code program into
system memory, execute the program, and debug it.
1. The debugger allows us to look at the contents of registers and memory locations
after our program runs.
2. It allows us to change the contents of register and memory locations and rerun the
program.
3. Some debugger allows us to stop execution after each instruction so we can check
or alter memory and register contents.
4. A debugger also allows us to set a breakout at any point in our program. When
we run a program, the system will execute instructions up to this break point and
stop. We can then examine register and memory contents to see if the results are
correct at that point. If the results are correct, we can move the break point to a
later point in our program. If results are not correct, we can check the program
up to that point to find out why they are not correct.
In short, debugger tools can help us to isolate problems in our program.
In such cases, it is not desirable to write procedures. For these cases, we can
use macros. Macro is also a group of instructions. Each time we “CALL” a macro
in our program, the assembler will insert the defined group of instructions in
place of the “CALL”. An important point here is that the assembler generates
machine codes for the group of instructions each time macro is called. So there
is not overhead time involved in calling and returning from a procedure. The
disadvantage of macro is that it generates inline code each time when the
macro is called which takes more memory. In this section we discuss the
procedures.
We often want a procedure to process some data or address variable from the
main program. For processing, it is necessary to pass these address variables
or data, usually referred as Passing Parameter Procedure. There are four ways
to pass parameters to and from the procedure
1. Using registers
2. Using general memory
3. Using pointers
4. Using stack
Passing Parameters Using Registers:
The data, to be passed is stored in the registers the procedure to process the
data.
Reentrant Procedure:
In some situations it may happen that procedure1 is called from main program,
procedure2 is called from procedure1 and procedure1 is again called from
procedure2. In this situation program execution flow reenters in the procedure1.
This type of procedures are called Reentrant Procedures. The flow of program
execution for reentrant procedure is shown in Fig. 8.3.
Recursive Procedure:
A recursive procedure is a procedure which calls itself. Recursive procedures
are used to work with complex data structures called trees. If the procedures is
called with N (recursion depth) = 3. Then the n is decremented by one after
each procedure CALL and the procedure is called until n = 0: Fig. 8.4 shows
the flow diagram and pseudo-code for recursive procedure.
Program Development and Execution:
The steps involved in Program Development and Execution of assembly
language programs. Fig. 8.1 shows these steps. The left side of the figure
shows the time period, at which each step in the overall process takes place.
The object code module contains the information about where the program or
module to be loaded in memory. If the object code module is to be linked with
other separately assembled modules then it contains additional linkage
information. At link time, separately assembled modules are combined into one
single load module, by the linker.
The linker also adds any required initialization or finalization code to allow the
operating system to start the program running and to return control to the
operating system after the program has completed.
Most linkers allow assembly language modules to be linked with object code
modules compiled from high-level languages as well. This allows the
programmer to insert a time-critical assembly language routines, library
modules into a program.
At load time, the program loader copies the program into the computer’s main
memory, and at execution time, program execution begins