First page Back Continue Last page Overview Graphics
What is the execution time required for the following loop? Assume a 16-MHz crystal.
- LDX #14 ;2 cycles
- DELAY: DEX ;1 cycle
- BNE DELAY ;3/1 cycle(s)
- Answer: total cycles is 2+13*(1+3)+(1+1) = 56.
- 56(125ns)= 7*8*125ns = 7 microseconds.
The LDX cycle instruction requires two bus cycles, the DEX one cycle. The BNE takes three cycles when branching but only one cycle when not branching. The total execution time required can be calculated using the following equation. The numbers in parenthesis represent cycle times.
LDX Loop w/branch back Loop w/no branch back
1 * (2) + 13 * (1 + 3) + 1 * (1 + 1) = # Bus Cycles
The number of bus cycles can be multiplied by the time for each bus cycle to get the total execution time.
In the above calculation it is assumed that the processor is making 16-bit memory accesses and that byte alignment is not a problem. This is the case when accessing internal memory. Using external memory configured for 8-bit accesses would extend the execution time.
Delay loops can be used for short delays, but would not be used for long delays since the processor is tied up during the delay and cannot be used for other tasks.