6.5 INSTRUCTION CYCLE
6.5.2 WHY DELAY LOOPS?
Instructions Cycles
MOV BX,N1 4
THERE: MOV CX,N2 4
HERE: LOOP HERE 17
DEC BX 2
JNZ THERE 16
The inner loop is that which corresponds to the LOOP instruction .It repeats N2 times ,which is the count in the CX register . The LOOP instruction plus a few overheads(
caused by the instructions MOV CX,N2 and DEC BX ) repeat N1 times ,which is the count of the outer loop .
.Thus a large delay can be obtained .To calculate N1 and N2 , the best way would be to make N2=FFFFH and then get a corresponding value for N1 .
For a total delay of 1 second,
Total cycles = N1 x [17x N2 +4+2+16]=N1 [22+17 N2]
If N2 =FFFFH i.e. 65,535 the calculation comes to 1114117 x N1 x .083 =1000 000 usecs
92471.711 xN1 =1000000 N1 =10.81
Thus a value of 11 (0BH) can be used in the place of N1 in the program.
Note : No values are subtracted to take into account the decreased number of cycles when a loop is exited .Thus ,this calculation is only appro ximate ,but the error is negligible .
6.5.2 WHY DELAY LOOPS?
What application is there for the exercise that we have just done ? Where are these delays to be used ?
Generating delays in this manner is called ‘software delay’.
One can generate a square wave using a soft ware delay .Suppose we have an output port with an address of 78H.See Example 6-4 .
x86 Chapter6 Page 33 Example 6-4
Generate a square wave of frequency 1 KHz at the output port with address 78H Solution:
AGAIN: MOV AL,0FFH OUT 78H,AL
CALL DELAY_1MS MOV AL,00
OUT 78H,AL
CALL DELAY_1MS JMP AGAIN
The above program assumes that a program named DELAY_1MS has been written and used as a procedure along with this . This procedure is like the programs in Examples 6-2 or 6-3 ,with a count which gives a delay of 1 msecs.
If a CRO is connected to any pin of the data bus of the output port ,a continuous square wave can be observed.
This is an application of software delay ,but in practical cases, we are more likely to use dedicated timer chips for generating square waves of any frequency ,which is more easy to program and gives more accurate delays.
In Chapter 5, Example 5-2 gets 20 temperature values from 20 input ports .Usually there should be a time delay between each measurement ,and a software delay can be used there .It is only necessary to write a procedure for a specific delay and call this delay between each measurement.
Key points of this chapter
8088 and 8086 processors are similar in most ways, except for three differences.
There are two modes of operation for the 8086-which are designated as minimum mode and maximum mode.
When in the minimum mode, the 8086 functions in a uniprocessor environment.
The address bus of the processor is multiplexed with the data bus ,and hence to use these buses separately ,de- multiplexing must be done.
The address bus ,data bus and control bus must be buffered to increase the driving capability of the buses.
An external clock generator is used to provide the clock and to synchronize the reset and ready signals with the clock
A machine cycle is a bus activity during which a specific operation is performed.
Reading and writing of memory and I/O are important bus cycles
A typical read/write machine cycle of 8086 is 4 T states long.
x86 Chapter6 Page 34
Wait states are inserted into machine cycles to accomodate slow memory or peripherals
In the minimum mode ,all control signals are obtained from the processor.
In the maximum mode, an external bus controller IC generates the important control signals
In the maximum mode ,there will be other processors in the system
There are pins on the 8086 on which other processors can request the service of the system bus.
It is important to know how many cycles are expended for the execution of each instruction.
The delay caused by instruction execution can be used to create delay loops
QUIZ
1. List out the differences between 8086 and 8088.
2. How is the mode of operation of the processor selected and what is the purpose of each mode?
3. Why are buffers/line drivers used in the address ,data and control lines?
4. What is the specification of the clock to be applied to the CLK pin of the processor?
5. What is the specification of the RESET signal to be given to the processor?
6. At what address does the 8086 wake up?
7. Why are RESET and READY signals applied to the clock generator IC?
8. When DT /R is high ,what is indicated?
9. What is the difference between the 74LS244 and 74LS245 ICs?
10. When is the READY pin sampled?
11. What is the difference in the interrupt signals INTR and NMI ? 12. What are the functions of the HOLD and HLDA pins?
13. When is the HOLD pin sampled?
14. How many wait cycles can be inserted in a bus cycle?
15. How can the processor be taken out of the HALT state?
16. What is ALE expected to do? What is the duration of ALE?
17. What is the purpose of the LOCK pin ?
18. Which are the control signals which are not available from the 8086 in the maximum mode?
19. Why is it that the time for fetching an instruction is not included in the instruction cycle time of an instruction?
20. What is the use of the NOP instruction?
EXERCISE
1) Draw the de- multiplexed and buffered data bus, address bus and the read/write control signals with latches and buffers connected.
x86 Chapter6 Page 35 2) Draw a logic diagram using NAND gates to get the signals IORD , IOWR , MEMRD and MEMWR from the three processor signals
IO
M / ,RD and WR .
3) Draw a memory write machine cycle showing the state of all important signals.
4) Redraw the above bus cycle with two wait states included.
5) Explain with relevant timing ,the operation of the RQ/GT pins.
6) In a typical write machine cycle, list out the activities occurring during each of the four T states.
7) Write a program for getting a delay of 100 msecs.
8) Write a program to generate a square wave at the LSB of the data bus of an output port with address F767H.
9) In a pressure monitoring environment ,10 pressure sensors have been connected. The pressure from these sensors have to be read at intervals of 5 msecs. Write a program to read the sensor values from input ports having address 0FF0H to 0FF9H