Professional Documents
Culture Documents
UNIT
8086 PROCESSOR
Syllabus
The 8086 is a 16-bit microprocessor chip designed by Intel and introduced on the market in
1978, which gave rise to the x86 architecture.
Intel 8088, released in 1979, was essentially the same chip, but with an external 8-bit data
bus (allowing the use of cheaper and fewer supporting logic chips), and is notable as the
processor used in the original IBM PC.
The first multi-chip 16-bit microprocessor was the National Semiconductor IMP-16,
introduced in early 1973.
An 8-bit version of the chipset was introduced in 1974 as the IMP-8. During the same year,
National introduced the first 16-bit single-chip microprocessor, the National
Semiconductor PACE, which was later followed by an NMOS version, the INS8900.
Intel followed a different path, having no minicomputers to emulate, and instead "upsized"
their 8080 design into the 16-bit Intel 8086, the first member of the x86 family which
powers most modern PC type computers.
Intel introduced the 8086 as a cost effective way of porting software from the 8080 lines,
and succeeded in winning much business on that premise.
The 8088, a version of the 8086 that used an external 8-bit data bus, was the
microprocessor in the first IBM PC, the model 5150.
Following up their 8086 and 8088, Intel released the 80186, 80286 and, in 1985, the 32-bit
80386, cementing their PC market dominance with the processor family's backwards
compatibility.
The integrated microprocessor memory management unit (MMU) was developed by
Childs et al. of Intel, and awarded US patent number 4,442,484.
The EU receives program instruction codes and data from the BIU, executes these
instructions, and store the results in the general registers.
By passing the data back to the BIU, data can also be stored in a memory location or written
to an output device.
The important point to note, however, is that because the EU is the same for each
processor, the programming instructions are exactly the same for each. Programs written
for the 8086 can be run on the 8088 without any changes.
The BIU is programmed to fetch a new instruction whenever the queue has room for one (with the
8088) or two (with the 8086) additional bytes.
The advantage of this pipelined architecture is that the EU can execute instructions almost
continually instead of having to wait for the BIU to fetch a new instruction.
PROGRAMING MODEL
As a programmer of the 8086 or 8088 you must become familiar with the various registers
in the EU and BIU. The data group consists of the accumulator and the BX, CX, and DX
registers
The data registers are normally used for storing temporary results that will be acted on by
subsequent instructions.
The pointer and index group are all 16-bit registers (you cannot access the low or high
bytes alone). These registers are used as memory pointers.
Register IP could be considered in the previous group, but this register has only one
function -to point to the next instruction to be fetched to the BIU. Register IP is physically
part of the BIU and not under direct control of the programmer as are the other pointer
registers.
Six of the flags are status indicators, reflecting properties of the result of the last arithmetic
or logical instructions.
Three of the flags can be set or reset directly by the programmer and are used to control the
operation of the processor. These are TF, IF, and DF.
The final group of registers is called the segment group. These registers are used by the BIU
to determine the memory address output by the CPU when it is reading or writing from the
memory unit. To fully understand these registers, we must first study the way the 8086/88
divides its memory into segments.
All general registers of the 8086 microprocessor can be used for arithmetic and
logic operations. The general registers are:
contains a data pointer used for based, based indexed or register indirect
addressing.
Count register consists of 2 8-bit registers CL and CH, which can be combined
together and used as a 16-bit register CX. When combined, CL register contains
the low-order byte of the word, and CH contains the high-order byte. Count
register can be used as a counter in string manipulation and shift/rotate
instructions.
Data register consists of 2 8-bit registers DL and DH, which can be combined
together and used as a 16-bit register DX. When combined, DL register contains
the low-order byte of the word, and DH contains the high-order byte. Data
register can be used as a port number in I/O operations. In integer 32-bit multiply
and divide instruction the DX register contains high-order word of the initial or
resulting number.
Overflow Flag (OF) - set if the result is too large positive number, or is too
small negative number to fit into destination operand.
Direction Flag (DF) - if set then string manipulation instructions will autodecrement index registers. If cleared then the index registers will be autoincremented.
Single-step Flag (TF) - if set then single-step interrupt will occur after the
next instruction.
Sign Flag (SF) - set if the most significant bit of the result is set.
Auxiliary carry Flag (AF) - set if there was a carry from or borrow to bits 0-3
in the AL register.
Parity Flag (PF) - set if parity (the number of "1" bits) in the low-order byte
of the result is even.
Carry Flag (CF) - set if there was a carry from or borrow to the most
significant bit during last result calculation.
Memories of 8086
Program, data and stack memories occupy the same memory space.
The total addressable memory size is 1MB KB. As the most of the processor
instructions use 16-bit pointers the processor can effectively address only
64 KB of memory.
Program memory
program can be located anywhere in memory.
Jump and call instructions can be used for short jumps within currently
selected 64 KB code segment, as well as for far jumps anywhere within 1
MB of memory.
All conditional jump instructions can be used to jump within approximately
+127 - -127 bytes from current instruction.
Data memory
The processor can access data in any one out of 4 available segments, which
limits the size of accessible memory to 256 KB (if all four segments point to
different 64 KB blocks).
Accessing data from the Data, Code, Stack or Extra segments can be usually
done by prefixing instructions with the DS:, CS:, SS: or ES: (some
registers and instructions by default may use the ES or SS segments instead
of DS segment).
Stack memory can be placed anywhere in memory. The stack can be located at
odd memory addresses, but it is not recommended for performance reasons (see
"Data Memory" above).
Reserved locations:
0000h - 03FFh are reserved for interrupt vectors. Each interrupt vector is a
32-bit pointer in format segment:offset.
MEMORY MAP
Still another view of the 8086/88 memory space could be as 16 64K-byte blocks beginning at hex
address 000000h and ending at address 0FFFFFh. This division into 64K-byte blocks is an arbitrary
but convenient choice. This is because the most significant hex digit increments by 1 with each
additional block. That is, address 20000h is 65.536 bytes higher in memory than address 10000h. Be
sure to note that five hex digits are required to represent a memory address.
The diagram is called a memory map. This is because, like a road map, it is a guide showing how the
system memory is allocated.
The physical address is 20 bits long and corresponds to the actual binary code output by the BIU on
the address bus lines. The logical address is an offset from location 0 of a given segment. When two
segments overlap it is certainly possible for two different logical addresses to map to the same
physical address. This can have disastrous results when the data begins to overwrite the subroutine
stack area, or vice versa. For this reason you must be very careful when segments are allowed to
overlap. You should also be careful when writing addresses on paper to do so clearly. To specify the
logical address XXXX in the stack segment, use the convention SS:XXXX, which is equal to [SS] *
16 + XXXX.
INTERRUPTS
NTERRUPT (HW AND SW)
What is an interrupt ?
An interrupt is the method of accessing the MPU by a peripheral device. An
interrupt is used to cause a temporary halt in the execution of a program. The MPU
responds to the interrupt with an interrupt service routine, which is a short program
or subroutine that instructs the MPU on how to handle the interrupt. When the
remainder in AH.If AX content is 4060H and BL is 02H, then the quotient is 2030H.
But the 8-bit AL register cannot hold this data. This results in automatic branching
to an ISS. It is an internal interrupt, and the 8086 branches to an ISS whose
interrupt Type number is 0.
Action taken by the 8086 when divide by zero error occurs is as follows.
1. Flag register value is pushed on to the stack.
2. CS value of the Return address and IP value of the Return address are pushed
on to the stack.
3. IP is loaded from contents of word location 0x4 = 00000H.
4. CS loaded from contents of next word location, 00002H.
5. Interrupt Flag and trap Flag are reset to 0.
The action taken by the ISS could be to display a suitable error message on the CRT
and then halt the proceedings. Or, it could be to set a bit in a memory location to
indicate an error, and then return to the interrupted program using the IRET
instruction.
useful for debugging a program. The action taken by the 8086 when T flag is set to 1, and an
instruction execution is completed is as follows.
2. CS value of the return address and IP value of the return address and IP value of
the return address are pushed on to the stack.
3. IP is loaded from the contents of word location 4x4 = 00010H.
4. CS is loaded from the contents of next word location.
5. Interrupt flag and Trap flag are reset to 0.
Thus a branch to ISS takes place. During the ISS, interrupts are disabled. At the end
of ISS, there will be an IRET instruction, returning back to the interrupted
program. Instructions in the ISS procedure perform the desired response to the
error condition.
Priority of Interrupts
The internal interrupts which result is an error, like Divide by Zero error, as well as
software interrupt instructions have the highest priority. Next priority is NMI. The
next lower priority is assigned to INTR. The lowest priority is assigned to single
Step interrupt. In reality, NMI is always serviced on top most priority.
ADDRESSING MODES
8086 Addressing Modes
The 8086 has 12 basic addressing modes(AM) and can be classified into
5 groups
I.
II.
III.
IV.
V.
2.Immediate
AM
In this mode a 8 or 16 bit data can be specified as part of the instruction
eg:MOV
CL,03H
MOV DX,0502H
II Addressing modes for data in memory (Memory mode)
3.Direct
AM
In this mode the 16 bit effective address (EA) is taken directly from the
displacement field of the instruction.This EA or displacement is the distance of the
memory location from the current value in the data segment (DS) register in which
the
data
are
stored.
The BIU shifts the [DS] 4 times to left & adds the EA to generate the 20 bit
physical
address.
eg:MOV
CX,START
MOV
START,BL
START can be defined as an address by using the assembler DB(Define Byte) or
DW(Define
Word)
pseudoinstructions.
Suppose
if
START=0040(16)
&
[DS]=3050(16)
then
305 0
Shift
Left
0 0 4 0 (EA)
20 bit
3 0 5 4 0 physical
address
4.Register
Indirect
AM
In this mode the EA is specified in either a pointer register or an index
register.The pointer register can be either base register(BX) or base pointer(BP)
and Index register can either be Source index(SI) or Destination index(DI) register
eg:MOV
[DI],BX
The instruction moves the 16 bit content of BX into a memory location offset by
the value of EA (EA is specified in DI) from the current contents in DS.
If
[DS]=5004(16)
[DI]=0020(16)
and
[BX]=2456(16)
then
5004
Shift
Left
0 0 2 0 (EA)
20 bit
5 0 0 6 0 physical
address
the contents of BX (2456) is moved into memory locations 50060(16) & 50061(16)
5.Based
AM
In this mode EA is obtained by adding a displacement (signed 8 bit or unsigned 16
bit) value to the contents of BX or BP.The segment registers used are DS & SS.
When Memory is accessed,the 20 bit physical address is computed from BX and
DS.On the other hand,when the stack is accessed,the 20 bit physical address is
computed from BP and SS.
eg:- MOV AL,START[BX] or MOV AL,[BX+START]
Where START=02H(8 bit displacement),BX=2000H
Now the 20 bit Physical address is computed from DS and EA
If [DS]=5004(16),then
2000H BX
02H
Displacement
2002H EA
5004
2 0 0 2 EA
5 2 0 4 0 20 bit Physical Address
0200H [BX]
1000H [SI]
08H
Displacement
1208H EA
3000
1 2 0 8 EA
3 1 2 0 8 20 bit Physical address
9.Direct AM
Here the port number is a 8 bit immediate operand.This allows fixed access to ports
numbered 0 to 255.
eg:- OUT 05H,AL
outputs [AL] to 8 bit port 05H
10.Indirect AM
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.
IV Relative Addressing Mode
11.
In this mode,the operand is specified as a signed 8 bit displacement,relative to
PC(Program Counter).
eg:- JNC START
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.
V Implied Addressing Mode
12.
Instructions using this mode have no operands.
eg:- CLC
this clears the carry flag to zero.
QUESTION BANK
1. How many bits does 8086 microprocessor have?
2. What is the size of data bus in 8086?
3. What is the size of address bus in 8086?
4. What is the max memory addressing capacity of 8086?
5. Which are the basic parts of 8086?
6. What are the functions of BIU?
7. What are the functions of EU?
8. How many pin IC 8086 is?
9. What IC8086 is?
10. What is the size of instruction queue in 8086?
11. What is the size of instruction queue in 8088?
12. Which are the registers present in 8086?
13. What is pipelining in 8086?
14. How many 16 bit registers are available in 8086?
15. Specify addressing modes for any instruction?
16. What is assembler directives?
17. What .model small stands for?
18. What is the supply requirement of 8086?
19. What is the relation between 8086 processor frequency & crystal
frequency?
20. Functions of Accumulator or AX register?
21. Functions of BX register?
22. Functions of CX register?
23. Functions of DX register?
24. How Physical address is generated?
25. Which are pointers present in this 8086?
26. Which is by default pointer for CS/ES?
27. How many segments present in it?
28. What is the size of each segment?
29. Basic difference between 8085 and 8086?
30. Which operations are not available in 8085?
31. What is the difference between min mode and max mode of 8086?
32. What is the difference between near and far procedure?
33. What is the difference between Macro and procedure?
34. What is the difference between instructions RET & IRET?
35. What is the difference between instructions MUL & IMUL?
36. What is the difference between instructions DIV & IDIV?
37. What is difference between shifts and rotate instructions?
38. Which are strings related instructions?
Appendix
1
2
(<element>)
Code Segment:
Label Definition:
<label name> :
Procedure Definition:
<procedure name> PROC {FAR | NEAR}
:
:
;***your (main/ sub) program here***
<procedure name> ENDP
Data Movement:
MOV
MOV
XCHG
LEA
Arithmetic Operation:
ADD {destination} , {source}
SUB {destination} , {source}
ADC {destination} , {source}
SBB {destination} , {source}
MUL {source}
IMUL {source}
DIV {source}
IDIV {<register> | <memory>}
NEG {<memory> | <register>}
INC {<memory> | <register>}
DEC {<memory> | <register>}
Program Control Flow:
JMP {<address> | <label> | <register>}
<type> PTR <expression>
CALL
<label>
RET
<immediate>
CMP
{destination}, {source}
JXX
{<address> | <label>}
LOOP
<label>
Logic Operation:
AND {destination}, {source}
OR
{destination}, {source}
XOR {destination}, {source}
NOT {destination}
<expression> <relational operator>
Rotation and Shifting:
SHL
SAL
<expression>
SAR
ROL
ROR
ROR
RCR
Interrupts:
INT <special code>
IRET
CLI
STI
Stack Segment:
Stack Definition:
DW
<size of stack>
dup
(<initial value>)
Stack Manipulation:
PUSH
POP
{<register> | <memory>}
{<register> | <memory>}
Macro Definition:
<Macro name>
MACRO
(arg1,arg2,....)
: : : : : ;***your macro here***
ENDM
LOCAL
(label_1,label_2,....)
Directives:
REPT
ENDM
IRP
ENDM
IRPC
<expression>
<statements>
<<parameter>, <arguments>>
<statements>
<<parameter>, <string argument>>
<statements>
ENDM
IFXX
<ELSE>
<condition>
<sequence of statements>
;optional
<sequence of statements>
ENDIF
Calling Sequences:
EXTRN <subprogram name> : type
PUBLIC <subprogram name>
***** END of Assembly Programming *****
Syllabus
8086 signals and timing
MIN/MAX mode of operation
Addressing memory and I/O
Multiprocessor configurations
System design using 8086
Pins 2 through 16 and pins 35 through 39 are used for the address bus.
Pins 35 through 38 are used by multiplexing to provide information or status about
the MPU. The status signals are labeled S3, S4, S5 and S6 as shown.
The data bus lines AD0 through AD15 are used at the start of the machine cycle to
send out addresses, and later in the machine cycle they are used to send or receive
data.
The 8086 sends out a signal called address latch enable or ALE on pin 25 to let
external circuitry know that an address is on the data bus.
The upper 4 bits of an address are sent on the lines labeled A16/ S 3 through A19/
S 6. Some of the control bus lines on a microprocessor usually have mnemonics
such as RD, WR and M/ IO.
Pin 32 of the 8086 is labeled RD. A tri-state active-low output signal on pin 32
indicates that the 8086 is reading data from memory or from a port.
Pin 29 has a label WR next to it. However, pin 29 also has a label LOCK next to it,
because this pin has two functions. The function of this pin and the functions of the
pins between 24 and 31 depend on the mode in which the 8086 is operating.
The operating mode of the 8086 is determined by the logic level applied to the MN
/ MX input on pin 33. If pin 33 is asserted high, then the 8086 will function in
minimum mode, and pins 24 through 31 will have functions shown in parentheses
next to the pins in fig. 8.
If the MN / MX pin is asserted low, then the 8086 is in maximum mode. In this
mode pins 24 through 31 will have the functions described by the mnemonics next
to the pins in fig. 8.
A tri-state active-low output signal on pin 29 indicates that MPU has put valid and
stable data on the data bus.
Pin 28 will function as M / IO. The 8086 will assert this signal high if it is reading
from or writing to a memory location, and it will assert a signal low if it is reading
from or writing to a port. In the maximum mode the control bus signals (S0, S1, S2 )
are sent out in encoded form on pins 26,27 and 28.
An external bus controller device decodes these signals to produce the control bus
signals required for a system, which has two or more microprocessors sharing the
same buses.If pin 21, the RESET input is made high, the 8086 will, no matter what it
is doing, reset its DS, SS, ES, IP and flag registers to all 0s. It will set its CS register
to FF. When the RESET signal is removed from pin 21, the 8086 will then fetch its
next instruction from physical address (FFFF0H). This address is produced in the
8086 Bus Interface unit (BIU) by shifting the FFFFH in the CS register 4 bits left by
adding the 0000H in the instruction pointer to it. The first instruction that has to be
executed after a reset is put at this address FFF0H.
8086 has two interrupt inputs, non-maskable interrupt (NMI) input on pin 17 and
the interrupt (INTR) input on pin 18. An active-high on any one of these pins will
cause
the 8086 to stop execution of its current program and go execute a specified
procedure.
At the end of the procedure it can return to executing the interrupted program.
The NMI
cannot be ignored, or masked, by the MPU. The INTR (interrupt request) is
maskable and
can be made to be ignored by the MPU through software control.
byte from memory or writing a word to a port requires some number of states. The
group
of states required for a basic bus operation is called a machine cycle. The total time
it
takes the 8086 to fetch and execute an instruction is called an instruction cycle. An
instruction cycle consists of one or more machine cycles. To summarize, an
instruction
cycle is made up of machine cycles, and a machine cycle is made up of states.
Two major bus cycles are the read bus cycle and the write bus cycle. The read bus
cycle is activated when the microprocessor is reading information from the
memory or an
I/O device. During the read bus cycle, there are normally four clock cycles T1 ,T2,
T3 and
T4. However, if the device outputting data to the MPU needs more time to send
the data,
a wait state (Tw) is initiated by placing extra clock cycles (Tws) between cycles T3
and T4.
Fetch-Execute cycle
The microprocessor has two primary functions. Fetch and execute. First it must
fetch or read the program instruction or data. This can take one or more bus cycles.
Once
it has fetched the necessary program instructions and data through the BIU, the
microprocessors next step is to execute the instructions. The EU receives the
instruction
from the instruction queue and executes it. Some instructions may take 2 clock
cycles to
execute, where as others may take as many as 100 clock cycles to execute. In older
microprocessors this left the bus idle while the MPU was executing a long
instruction, as
shown in the fig. 10. however, since the 8086 MPU is broken up into two
functional units,
the BIU and EU, it avoids much of the idle time required by older microprocessors.
It
does this by having the BIU pre fetch instructions and place them into the
instruction
queue and data registers while the EU is executing the program instructions.
Therefore,
while the bus is busy during a read cycle, the EU can be executing the previous
instructions. When the bus is busy during a write cycle, the EU can be executing
another
instruction. This greatly increases the effective speed of the entire system.
In the bus timing diagram, data transmit / receive signal goes low (RECEIVE) for
Read operation. To validate the data, DEN* signal goes low. The Address/ Status
bus carries A16 to A19 address lines during BHE* (low) and for the remaining time
carries Status information. The Address/Data bus carries A0 to A15 address
information during ALE going high and for the remaining time it carries data. The
RD* line going low indicates that this is a Read operation. The curved arrows
indicate the relationship between valid data and RD* signal
The TW is Wait time needed to synchronize the fast processor with slow memory
etc. The Ready pin is checked to see whether any peripheral needs more time for
data transmission.
This is the same as Read cycle Timing Diagram except that the DT/R* line goes
high indicating it is a Data Transmission operation for the processor to memory /
peripheral. Again DEN* line goes low to validate data and WR* line goes low,
indicating a Write operation.
The HOLD and HLDA timing diagram indicates in Time Space HOLD (input)
occurs first and then the processor outputs HLDA (Hold Acknowledge).
MAXIMUM MODE
Here MRDC* signal is used instead of RD* as in case of Minimum Mode S0* to
S2* are active and are used to generate control signal.
Here the maximum mode write signals are shown. Please note that the T states
correspond to the time during which DEN* is LOW, WRITE Control goes LOW,
DT/R* is HIGH and data output in available from the processor on the data bus.
Request / Grant pin may appear that both signals are active low. But in reality,
Request signal goes low first (input to processor), and then the processor grants
the request by outputting a low on the same pin.
Address Bus
An address is a unique location in memory. It is like a mailbox in the post
office,
where each mail box has its own unique number to identify its location.
An address bus consists of 16,20,24 or more parallel signal lines. On these
lines the CPU sends out the addresses of the memory location that is to be
written to or read from.
In the 8086 theaddress is determined by a 20-bit number.
This gives us 220 possible address locations, or1,048,576 bytes of memory.
An address bus is made up of 20 wires, or conductors, labeled A0 through A19 ,
with A0 as the LSB and A19 as the MSB. It is used to locate or find information in
Data Bus
A data bus is used to move information ( data and instruction ) from the MPU to
memory and other devices. This is referred to as a write operation. The data bus is
also
used to receive information into the MPU. This is called as a read operation.
Because the
data bus receives and transmits information, it is known as a bi-directional bus.
However,
it cannot receive and transmit data at the same time.
The Intel 8086 has a 16-bit data bus labeled D0 to D15, where D0 is the LSB and
D15 is the MSB. The 8086 microprocessor multiplex the address and data buses.
Multiplexing is the process of using the same wires or pins to do different things at
different times. When acting as a data bus, the signal lines carry read/write
information for
memory or input/output information for I/O devices. When acting as an address
bus, the
same signal lines are used to locate information.
Control Bus
22
The CPU sends out signals on the control bus to enable the outputs of addressed
memory devices or port devices. The control line determines the sequence of
operations to
be performed. The control bus consists of 4 to 10 parallel signal lines. Typical
control bus
signals are memory read, memory write, I/O read, and I/O write. To read a byte of
data
from a memory location, for example, the CPU sends out the address of the desired
byte
on the address byte and then sends out a memory read signal on the control bus.
The
memory read signal enables the addressed memory device to output the byte of
data on to
the data bus where it is required by the CPU.
23
Chapter 5
read operation.
Memory classification
Memory can be classified into three general types, ROM and RAM. ROM stands
for read- only memory. ROM generally contains permanently stored data that
cannot be
changed. It can be read but not written into. The main feature of ROMs is that they
are
non-volatile, which means that the information stored in them is not lost when the
power
is removed.
RAM, on the other hand, is memory that can be read from or written to. RAM
stands for random-access memory, but since ROMs are also random access, the
major
difference is that RAM is memory that can be read or written to. RAM is actually
read/write memory. RAM memory is volatile memory, that is, it is lost whenever
the
power is switched off.
ROM
ROMs can be classified into three general types. A maskable ROM is a ROM that
is programmed with information or data by the manufacturer. Once programmed
these
data bits cannot be altered or changed. A programmable ROM, or PROM, is a
device that
can be programmed by a user. Once programmed, the data in a PROM, like a
ROM,
cannot be altered or changed . An erasable PROM, or EPROM, is a type of ROM
that
24
can be programmed by an user but whose data may be erased or changed with use
of
specialized equipment.
A summary of the different types of ROMs is given below:
RAM
RAM or read/write memory, is a type of volatile memory from which data can be
read and into which data can be written. RAM can be classified as either Static or
dynamic. A Static RAM is essentially a matrix of flip-flops. Therefore, we can write
a new
data word in a RAM location at any time by applying the word to the flip-flop data
input
and clocking the flip-flops. The stored data word will remain on the flip-flop
outputs as
long as the power is left on. This type of memory is volatile because data is lost
when the
power is turned off. These types of storage device is called static RAM. In dynamic
RAMs, binary 1s and 0s are stored as an electrical charge or no charge on a tiny
capacitor.
The internal capacitance of a MOSFET is great enough to make it appear that a
small
capacitor (a few pico-farads ) exists in the MOSFET. Each memory cell is
essentially a
single MOSFET. A logic 1 or a charged capacitor must be refreshed, or recharged,
at least
once every 2 ms, or the capacitor will lose its charge and the data.
Addressing Modes
The different ways that a processor can access data are referred to as its
addressing modes. It is the way by which the location of the operand is determined.
How
26
segment is the one most often used. Fig 11(a) shows a graphic form how EA is
added to
the data segment base to point an operand in the memory. The fig 11(b) shows how
the
20-bit physical address is generated by the BIU. The starting address for the data
segment
in fig 10 (b) is 2000H so that the data segment register will contain 2000 H. The
BIU
shifts the 2000 H four bit positions left and adds the effective address, 437AH, to
the
result. The 20-bit physical address sent out to memory by the BIU will then be
2437AH.
The physical address can be represented either as a single number, 2437AH, or in
the
segment base; offset form as 2000 : 437AH
example. The brackets around the 437AH are shorthand for the contents of the
memory
location at a displacement from the segment base of. When executed, this
instruction will
copy the contents of the memory location, at a displacement of 437AH from the
data
segment base into the CL register. The actual 20-bit physical memory address will
be
produced by shifting the data segment base in DS four bits left and adding the
effective
27
address 437AH to the result. Fig 10(b) shows how the operation is done. This
addressing
mode is called direct because the displacement of the operand from the segment
base is
specified directly in the instruction.
Another example of this addressing mode is the instruction MOV BX, [437AH].
When executed, this instruction copies a word from memory into BX register.
Since each
memory address of the 8086 represents a byte of storage, the word must come
from two
memory locations. The byte at a displacement of 437AH from the data segment
base will
be copied into BL. The contents of the next higher address, displacement 437BH
will be
copied into BH register. The 8086 will automatically access the required number of
bytes
in memory for a given instruction.
The previous examples showed how the direct addressing mode can be used to
specify the source of an operand. It can also be used to specify the destination of an
operand. The instruction MOV[437AH], BX for example will copy the contents of
the
BX register to two memory locations in the data segment. The contents of BL will
be
Segmentation
Intel has designed the 8086 family devices to use memory segmentation. By
working with only 64 K bytes segments of memory at a time, the 8086 only has to
work
with 16-bit effective addresses to access any location in the segment. In other
words,
because of the segmentation scheme the 8086 has to manipulate and store 16-bit
address
28
components. Also, in a time-share microcomputer system several users share a
CPU. The
CPU works on one users program for perhaps 20 milliseconds. After working for
20 m
sec on one users program, it then works on the next users program for 20
milliseconds.
After working for 20 milliseconds for each of the other users, the CPU comes back
to
working on the first users program again. Each time the CPU switches from one
users
program to the next it must access a new section of code and sections of data.
Segmentation makes this switching quite easy. Each users program can be
assigned a
separate set of logical segments for its code and data. The users program will
contain
offsets or displacements from these segment bases to change from one users
program to a
second users program all that has to be done is to reload the four segment
registers with
the segment base address assigned to the second users program. In other words,
segmentation makes it easy to keep users programs and data separate from each
other,
and segmentation makes it easy to switch from one users program to another
users
program.
A serial I/O port is quite different. The data bits are lined up and transmitted in
single file fashion one bit at a time. This technique will be slower than parallel port
design.
Regardless of the I/O port design- parallel or serial- the microprocessor must be
synchronized to the speed of the peripheral. Some peripherals like printers and
plotters,
cannot accept data as the microprocessor would like to output it. On the other hand
floppy- disk drives and Winchester disks may require data faster than the processor
can
supply it.
The major types of I/O operations are;
Parallel I/O.
Serial I/O.
Programmed I/O.
Interrupt-Driven I/O.
Direct Memory Access.
Parallel I/O
The hardware requirements for a Parallel I/O port are similar to those of a RAM or
ROM interface. When the CPU performs an output instruction (I/O write cycle)
the data
on the bus must be stored by the port. When an input instruction ( I/O read cycle)
is
executed, the I/O port must gate its data on to the data bus lines. Just as each
memory
location has its own (memory) address, each I/O port has its own ( port) address.
The 8086 has two I/O instructions IN AL ( or AX),port and OUT port, AL (or
AX). There are two forms each of the instruction. In the direct form, IN AL (or AX)
port
or OUT port, AL ( or AX), the I/O port address is supplied within the instruction
and
restricts the access to ports with adds between 0 and 255. The indirect Form, IN AL
( or
AX), DX and OUT DX, AL ( or AX) uses register DX to hold the port address. This
allows access to the full range of I/O ports from 0 to 65,535.
The advantage of the indirect form is that an I/O procedure can be setup and
shared between several peripherals by passing the port address ( in register DX) to
the
procedure.
The address bus carries the port address on A0-A7 for direct I/O cycles, and A0 A15 for indirect I/O cycles. The D0-D7 data bus lines are used to transfer data form
evenaddressed
ports, and D8-D15 are used for odd-addressed ports. The BHE and A0 are used to
identify the type of transfer.
In the minimum mode, the condition M/I/O =0 is used to identify the current bus
cycle as an I/O operation. RD and WR then indicate the direction of data flow.
In the maximum mode the 8288 bus controller provides separate I/O read and
write
commands.
Table 2 indicates the two forms of each instruction.
39
software using any of the memory read or write instructions. For example, the
instruction
MOV BH, MEMBDS becomes an input instruction ( input the data at port
MEMBDS
to register BH). Indirect I/O is also possible. The instruction sequence.
LEA SI, MEMWDS : Point SI at the port
MOV (S.I), CX : output CX to port
allows CX to be output to the 16-bit port at address DS:MEMWDS.
40
The advantage of memory- mapped I/O is the large number of instructions and
addressing modes available for refreshing memory. This is compared to the single
input
and output commands available with an I/O mapped port.
Serial I/O
The two basic methods used for serial data transmission and reception are
Asynchronous and Synchronous serial communication.
computer over a two-or three- conductor cable. Because, even the fastest typist
cannot
exceed data rates of 60 to 100 words per minute, it is a good match for the slow
transmission rate of the serial port. At some times the serial port will be required to
transfer data at 10 to 20 characters/S, but at other times the data rate may be only 1
to 2
characters/S. Most of the time the key board is not in use and the data rate is zero.
Because of this erratic data rate, an asynchronous communications protocol must
be
established.
The accepted technique for asynchronous serial communication is to hold the
serial output line to a logic 1 level until data is to be transmitted. Each character is
required to begin with a logic 0 for one bit time. The first bit is called the start bit
and is
used to synchronize the transmitter and receiver. The data is sent least significant
bit first
and framed between a start bit (always a 0) and one or two stop bits ( always a 1).
The
start and stop bits carry no information but are required because of the
asynchronous
nature of the data. Fig. 14 illustrates how the data byte 7BH would look when
transmitted
in the asynchronous serial format.
41
Writing a program compatible with all the different asynchronous communication
protocols can be a difficult task. It is also an inefficient use of the microprocessor, as
much
of its time will be spent in timing loops waiting to transmit or receive another
character.
Because of this, the semiconductor companies have developed the universal,
Asynchronous Receiver/Transmitter (UART)
It is interesting to note that to the microprocessor a serial port (the UART)
appears as a conventional parallel port. When the transmitter buffer is empty, all
the bits in
the word to be transmitted are output to the port at once ( in parallel) similarly, all
bits of
the received word are input at once when the received data is ready.
The job of converting the data from serial to parallel, or parallel to serial, has been
transferred to the UART.
Bisync Protocol
Because there is no start bit, a special Sync, character is required to all
synchronous serial formats. This character tells the receives that data is about to
follow.
The USART ( Universal Synchronous/Asynchronous Receiver/Transmitter),
accordingly,
must have a special hunt or search mode so that the Sync. Character can be
found.
42
In Bisync protocol several special characters are used to control the data transfer.
Fig 15 illustrates one frame of a Synchronous message.
In fig. 15 two sync. Characters are output followed by STX- start of text, ETX
signifies end of text BCC is a block check character used for error detector. Pad is
the
character output when no data is being transmitted and corresponds to the mark
output
in asynchronous serial.
The SDLC receiver searches for the beginning flag (01111110) as its sync
character. An 8-bit address field follows, allowing each frame to be addressed to a
particular station among a network of stations. Control characters are identified by
a
sequence of six or more logic 1s. The information field may be of any format. The
transmitter will automatically insert 0s in this field if five or more log 1s should
appear in
sequence. This will avoid inadvertent control characters appearing in the
information
field. The receiver automatically deletes these 0s. The 16-bit frame check is used
for error
detection. The frame ends with the ending flag.
Programmed I/O
43
Program instructions are controlling the transfer of data during the IN and OUT
operations. The software therefore initiates, as well as, controls the process of data
transfer. The hardwares responsibilities are confined to merely performing the
necessary
operations. The appropriate device is first checked in the device interface to
determine
whether it is ready. Device readiness must be tested because the CPU is much
faster than
peripheral devices. The test is followed by a conditional skip instruction. If the
ready flag
is 1 (device ready), the program proceeds to the next step. If the Ready Flag is 0,
the
program loops back to the test instruction. The CPU, therefore, waits for a slow
device by
continually testing the readiness of the device, until it reports ready. When the I/O
device
is ready, the data transfer operation takes place. Immediately after the transfer of
one
character, the CPU reset the ready Flag to 0. The device then sets the Flag back to
1,
when it is again ready to receive the data.
Programmed data transfer has the advantage that it allows simple hardware
interfaces, because most of the management of the I/O operations is performed by
software. The disadvantage of this technique is that valuable CPU time is wasted
while
the CPU waits for the peripheral device to get ready.
resources of the processor are devoted to waiting for this flag. No other task can be
performed. If the peripheral is READY once in every 10,000 sec, the CPU will
spend
most of its time idling. A more logical approach would be to have the peripheral
tell the
CPU when it is ready. This is the purpose of the microprocessors interrupt input.
An
interrupt is used to cause a temporary halt in the execution of a program. The
microprocessor responds to the interrupt with an Interrupt Service Sub-routine
(ISS)
which is a short programme or a subroutine that instructs the microprocessor on
how to
handle the interrupt.
Fig. 17 diagrams the CPUs response to an interrupt. During time 1 the processor
is assumed to be executing its main task. At time 2 the peripherals READY flag
causes an
interrupt to occur. After finishing the current instruction at time 3, the CS, IP and
flag
44
registers are pushed on to the stack at time 4. Control then transfers to the ISS at
time 5.
During time 6, the ISS is executed, terminating with the instruction IRET (interrupt
return). The CS, IP and flag registers are recovered from the stack during time 7
and the
original task is resumed at time 8.
If we assume that 100 s is required to respond to the interrupt and supply the
peripheral with data, then in the case of a 10,000 s per character printer, 9900 s
will be
available to the processor for its main task.
The 8086 has two interrupt pins labeled INTER and NM1. NM1 is a nonmaskable
interrupt, which means that it requires an immediate response from the processor
and it
cannot be blocked. INTR is maskable via the IF flag. Only when this flag is set will
interrupts on this input be accepted. Interrupts can be generated by both hardware
and
software. Interrupts are also prioritized to allow for the case when more than one
interfere
Because the NMI input is nonmaskable, care must be taken when using this
interrupt. This is because there may be some programs which we do not want to
interruptreading
or writing data to a disk drive, for example. For this reason, NMI input is
normally reserved for catastrophic events like memory error or impending power
failure.
45
Since the main purpose of DMA operation is to transfer data between external
devices and memory without involving the MPU, another device is required. This
device is
called a DMA controller. The DMA controller must be capable of performing read
and
write operations in the same manner as the MPU. Therefore, the DMA controller
is
actually a special- purpose microprocessor whose only task is to perform highspeed data
transfer between memory and an external device. The major difference between
an I/O
program controlled transfer and DMA is that data transfer does not employ the
registers
of the CPU.
The primary advantage of the DMA data transfer technique is that it provides an
efficient transfer of large amount of data between storage devices and the main
memory
without involving the CPU.
Several DMA transfer combinations are possible.
1. Memory to peripheral.
2. Peripheral to memory.
3. Memory to memory.
4. Peripheral to peripheral
DMA request takes precedence over all other bus activities, including interrupts. In
fact, no interrupt- maskable or non-maskable- will be recognised during a DMA
operation.