ALT by Bilal Ahmed Shaik - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

img134.png

 

  Assembly Loops

 

  The JMP instruction can be used for implementing loops. For example, the following code snippet can be used for executing the loop-body 10 times.

 

img135.png 

  The processor instruction set however includes a group of loop instructions for implementing iteration. The basic LOOP instruction has the following syntax:

 

img136.png 

  Where, label is the target label that identifies the target instruction as in the jump instructions. The LOOP instruction assumes that the ECX register contains the loop count. When the loop instruction is executed, the ECX register is decremented and the control jumps to the target label, until the ECX register value, i.e., the counter reaches the value zero.

 

  The above code snippet could be written as:

 

img137.png 

  Example:

 

  The following program prints the number 1 to 9 on the screen:

 

img138.png

img139.png