Advertisement
Masum6035

Nested Loop

Apr 29th, 2021
1,483
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;nested loop practise
  2.  
  3. .model small   
  4. .stack 100h    
  5. include 'emu8086.inc'
  6.  
  7. .data
  8.  
  9. n_line db 0ah,0dh,"$"   ;for new line  
  10. rows db 5d
  11. columns db 3d
  12. i db ?
  13. j db ?
  14.  
  15. .code
  16.  
  17. main proc
  18.     mov ax,@data   
  19.     mov ds,ax    
  20.  
  21.            
  22.     print "MasumBhai"  
  23.     printn
  24.      
  25.     ;for (int i = 1; i <= rows; ++i)
  26.     ;Assembly type
  27.    ; int i;
  28.    ; for(;i<=rows;)
  29.    ; {
  30.    ;   i++
  31.    ; }  
  32. @first_loop_init:
  33.     mov i,1d  
  34.     mov bl,rows;
  35. @first_loop:
  36.     cmp i,bl
  37.     jg @stop
  38.         @second_loop_init:
  39.             mov j,1d;
  40.             mov cl,columns
  41.         @second_loop:
  42.              cmp j,cl
  43.              jg @second_loop_finish    
  44.                     print "# "  
  45.              inc j
  46.              jmp @second_loop
  47. @second_loop_finish:
  48.     lea dx,n_line ;new line
  49.     mov ah,9
  50.     int 21h
  51.            
  52.     inc i
  53.     jmp @first_loop
  54.      
  55.        
  56. @stop:    
  57.     mov ah,4ch
  58.     int 21h     ;terminate with return code
  59. main endp
  60. end main
  61.  
Advertisement
RAW Paste Data Copied
Advertisement