Page 144 - DCAP210_INTRODUCTION__TO_MICROPROCESSORS
P. 144

Introduction to Microprocessors


                  Notes          10.1 Looping, Counting and Indexing

                                 When repetitive task are considered, computers are more efficient than human beings fast and
                                 accurate, when have to add hundreds numbers or transferring a thousand bytes of data.
                                 Looping is the programming technique used to instruct the microprocessor to repeat tasks. A
                                 loop is the procedure which asks the microprocessor to change the sequence of execution and
                                 perform the task repeatedly. These set of instructions also include counting i.e., how many times
                                 the task should be repeated and indexing is use to keep track of the sequential execution after the
                                 jump. Counting is technique allows programmer to count how many times the instruction/set of
                                 instructions are executed. Indexing allows programmer to point or refer the data stored in
                                 sequential memory locations one by one.
                                 Loops can be classified into two jumps:

                                 1. Continuous loop-repeats the tasks continuously.
                                 2. Conditional loop-repeats the task until certain data conditions are met.

                                 10.1.1 Continuous Loop

                                 A continuous loop is setup by using the unconditional jump instructions. The unconditional
                                 jump instruction creates a continuous loop which can be stopped only by the resetting of the
                                 system.

                                                      Figure 10.1: Flowchart of Continuous Loop.




















                                 10.1.2 Conditional Loop

                                 A conditional loop is setup by the conditional jump instructions. 'These instruction check flags:
                                 zero, carry, sign etc. and repeat the specific tasks if the conditions are satisfied. These loop usually
                                 include counting and indexing.
                                 The conditional loops are executed in the following steps:

                                 Step 1: Counter is setup by loading appropriate value in the register.
                                 Step 2: Counting can be performed either by incrementing or decrementing the counter.
                                 Step 3: Loops are setup by a conditional jump instructions.
                                 Step 4: Flag denotes the end of counting.

                                 It is easier to count down to zero than to count up. In counting down, the zero flag is set when the
                                 register value becomes zero. In counting up requires the compare instruction.





        138                              LOVELY PROFESSIONAL UNIVERSITY
   139   140   141   142   143   144   145   146   147   148   149