;How to draw a (hollow) square of a given size and color at a given location on the screen.
;Note how the order of drawing doen't matter.
;After drawing the square, we pause, and upon enter erase the top line, pause again.
;The input is top left pixel of the square is: (x,y)
IDEAL
MODEL small
STACK 100h
DATASEG
x      dw  40
y      dw  40 
sqsz   equ 15   ;square size in pixels. 
color  db  0Dh  ;0Ch-red, 9- light blue, 0Ah - light green, 0Dh - light magenta, 0Eh - yellow

CODESEG
start:
     mov ax, @data
     mov ds, ax 
;------------------------------------------------------------------------------------------
; Graphic mode
     mov  ax,13h
     int  10h

     mov  al,[color]
;horizontal upper 
     mov  cx,sqsz   
l1:  push cx        ; loop to draw upper side (one pixel at a time. x - horizontal grows)
     mov  bh,0h  
     mov  cx,[x]
     mov  dx,[y]
     inc  [x]
     mov  ah,0ch     
     int  10h
     pop  cx
     loop l1
;vertical left 
     mov  cx,sqsz    
l2:  push cx
     mov  bh,0h  
     mov  cx,[x]
     mov  dx,[y]
     inc  [y]
     mov  ah,0ch  
     int  10h
     pop  cx
     loop l2   
;Horizontal bottom
     mov  cx,sqsz    
l3:  push cx
     mov  bh,0h  
     mov  cx,[x]
     mov  dx,[y]
     dec  [x]
     mov  ah,0ch  
     int  10h
     pop  cx
     loop l3  
;Horizontal bottom
     mov  cx,sqsz    
l4:  push cx
     mov  bh,0h  
     mov  cx,[x]
     mov  dx,[y]
     dec  [y]
     mov  ah,0ch  
     int  10h
     pop  cx
     loop l4              
; Wait for key press
     mov  ah,00h  
     int  16h
     inc  bl
;Erase the upper line
     mov  al,0
     mov  cx,sqsz 
     inc  cx  
l5:  push cx        ; loop to draw upper side (one pixel at a time. x - horizontal grows)
     mov  bh,0h  
     mov  cx,[x]
     mov  dx,[y]
     inc  [x]
     mov  ah,0ch     
     int  10h
     pop  cx
     loop l5     
; Wait for key press
     mov  ah,00h  
     int  16h
     inc  bl     

; Return to text mode
     mov  ah,0
     mov  al,2
     int  10h   
;------------------ end of my code   
exit:
   mov ax, 4c00h
   int 21h
END start  