CS 206D Computer Organization Lab3

7
CS 206D Computer Organization Lab3 CS 111

description

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. - PowerPoint PPT Presentation

Transcript of CS 206D Computer Organization Lab3

Page 1: CS 206D Computer Organization Lab3

CS 111

CS 206D Computer OrganizationLab3

Page 2: 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 loopLOOP destnation_lable

Page 3: CS 206D Computer Organization Lab3

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.

Page 4: CS 206D Computer Organization Lab3

For loop

CS 111

• Example: Write some code to display a row of 20 stars.

• Solution: Pseudo code:

FOR 20 times DO display '*'END_IF

Page 5: CS 206D Computer Organization Lab3

For loop

CS 111

• Example: Write some code to display a row of 20 stars.

It can be coded as follows:MOV CX, 20 ; initialize CX to 80MOV AH, 2MOV DL, '*'

TOP:INT 21hLOOP TOP

Page 6: CS 206D Computer Organization Lab3

Exercise :

CS 111

• Example: Write some code to display all English alphabets (A TO Z)

Page 7: CS 206D Computer Organization Lab3

Exercise :

CS 111

• Example: Write some code to display all English alphabets (A TO Z)