04-02-2013, 02:00 PM
Counters & Time Delays
Counters.ppt (Size: 3.47 MB / Downloads: 25)
Counters
Using counters programmer can specify that how many times an instruction (or set of instructions) is to be executed.
A loop counter is set up by loading a register with a certain value
Then using the DCR (to decrement) and INR (to increment) the contents of the register are updated.
A loop is set up with a conditional jump instruction that loops back or not depending on whether the count has reached the termination count.
Indexing
Indexing means pointing or referencing objects with sequential numbers. In a library, books are arranged according to numbers, and they are referred to or sorted by numbers. This is called indexing.
Similarly, data bytes are stored in memory locations and those data bytes are referred to by their memory locations.
E.g., a list of numbers is stored in sequential memory locations. To access this list we need the address of first element and total number of elements in the list. We can use a register pair as an index by loading this address into the pair and then incrementing it to access elements of the list.
Delays
Each instruction passes through different combinations of Fetch, Memory Read, and Memory Write cycles.
Knowing the combinations of cycles, one can calculate how long such an instruction would require to complete.
The table in Appendix F of the book(Gaonkar) contains a column with the title B/M/T.
B for Number of Bytes
M for Number of Machine Cycles
T for Number of T-State.
Using a Register Pair as a Loop Counter
Using a single register, one can repeat a loop for a maximum count of 255 times.
It is possible to increase this count by using a register pair for the loop counter instead of the single register.
A minor problem arises in how to test for the final count since DCX and INX do not modify the flags.
However, if the loop is looking for when the count becomes zero, we can use a small trick by ORing the two registers in the pair and then checking the zero flag.
Hexadecimal counter
This problem has two parts; the first is to set up a continuous down-counter, and the second is to design a given delay between two counts.
The hexadecimal counter is set up by loading a register with an appropriate starting number and decrementing it until it becomes zero. After zero count, the register goes back to FF because decrementing zero results in a (-1), which is FF in 2’s complement.
The 1 ms delay between each count is set up by using delay techniques.