LOOPING, COUNTING AND INDEXING
LOOPING:
The programming technique used to instruct the microprocessor to repeat tasks is called
looping.
This task is accomplished by using jump instructions.
CLASSIFICATION OF LOOPS:
1.continuous loop
2.Unconditional loop
CONTINUOUS LOOP:
repeats a task continuously.
A continuous loop is set up by using the unconditional jump instruction
A program with a continuous loop does not stop repeating the tasks until the system is reset.
CONDITIONAL LOOP:
A conditional loop is set up by a conditional jump instructions.
These instructions check flags(Z,CY,P,S) and repeat the tasks if the conditions are satisfied.
These loops include counting and indexing.
CONDITIONAL LOOP AND COUNTER:
A counter is a typical application of the conditional loop.
A microprocessor needs a counter,flag to accomplish the looping task.
Counter is set up by loading an appropriate count in a register.
Counting is performed by either increment or decrement the counter.
Loop is set up by a conditional jump instruction.
End of counting is indicated by a flag.
CONDITIONAL LOOP,COUNTER AND INDEXING:
Another type of loop which includes counter and indexing .
INDEXING:
pointing of referencing objects with sequential numbers.
Data bytes are stored in memory locations and those data bytes are referred to by their
memory locations.
Example:
Steps to add ten bytes of data stored in memory locations starting ata given location and
display the sum.
The microprocessor needs
1. a counter to count 10 data bytes.
2. an index or a memory pointer to locate where data bytes are stored.
3. to transfer data from a memory location to the microprocessor(ALU)
4. to perform addition
5. registers for temporary storage of partial answers
6. a flag to indicate the completion of the stack
7. to store or output the result.