70 likes | 221 Views
CS 206D Computer Organization Lab3. LOOP Instruction. The LOOP instruction can be used to implement a for loop. Syntax : ; initialize CX to loop_count destnation_lable: ; body of the loop LOOP destnation_lable. LOOP instruction.
E N D
CS 206D Computer Organization Lab3 CS 111
LOOP Instruction • The LOOP instruction can be used to implement a for loop. • Syntax: ; initialize CX to loop_count destnation_lable: ; body of the loop LOOP destnation_lable CS 111
LOOP instruction • The counter for the loop is the register CX, which is initialized to loop_count. • Execution of the LOOP instruction causes CX to be decremented automatically. • If (CX < > 0) control transfers to destination_label else the next instruction after LOOP is done. CS 111
For loop • Example: Write some code to display a row of 20 stars. • Solution: • Pseudo code: • FOR 20 times DO • display '*' • END_IF CS 111
For loop • Example: Write some code to display a row of 20 stars. It can be coded as follows: MOV CX, 20 ; initialize CX to 80 MOV AH, 2 MOV DL, '*' TOP: INT 21h LOOP TOP CS 111
Exercise : • Example: Write some code to display all English alphabets (A TO Z) CS 111
Exercise : • Example: Write some code to display all English alphabets (A TO Z) CS 111