Presentation is loading. Please wait.

Presentation is loading. Please wait.

CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#7) By Dr. Syed Noman.

Similar presentations


Presentation on theme: "CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#7) By Dr. Syed Noman."— Presentation transcript:

1 CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#7) By Dr. Syed Noman

2 Implementing loop without loop statement Printing ‘*’ ten times on the screen mov ah,2 mov dl,’*’ mov cx,10 disp_char: int 21h dec cx cmp cx,0 jne disp_char 2

3 General format for using loop instruction mov cx, count ; count = # of times to repeat loop start_loop: ; use any label name ; while cx > 0 ; repeat loop body instructions loop start_loop 3

4 Implementing loop with loop statement mov ah,2 mov dl, ‘*’ ; al = ‘*’ mov cx, 10 ; cx = 10 ; loop count disp_char: int 21h; display ‘*’ loop disp_char ; cx = cx - 1, if (cx != 0) Here, cx is initialised to 10, the number of iterations required. The instruction loop disp_char first decrements cx and then tests if cx is not equal to 0, branching to disp_char only if cx does not equal 0. 4

5 Program to print name 10 times.model small.data myName db 13,10,‘Dr. Syed Noman$’.code mov ax,@data mov ds,ax mov cx,10 mov ah,9 mov dx, offset myName again: int 21h loop again mov ax,4c00h int 21h end 5

6 Program print digits from 0 to 9.model small.code mov cx,10 mov ah,2 mov dl,30h; mov dl, ‘0’; mov dl,48; mov dl, 00110000b again: int 21h inc dl loop again mov ax,4c00h int 21h end 6

7 Program print even numbers from 0 to 9.model small.code mov cx,5 mov ah,2 mov dl,30h again: int 21h add dl,2 loop again mov ax,4c00h int 21h end 7


Download ppt "CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#7) By Dr. Syed Noman."

Similar presentations


Ads by Google