; Drawing an X with 4 parameters: 
; 1 - how many pixels from the left of the screen 
; 2 - how many pixels from the left of the screen 
; 3 - size in pixels of the 'leg' (4 legs of the X)
; 4 - color of the X

; There are four required data segment variables.

IDEAL
MODEL small
STACK 100h
DATASEG

; Four required DATASEG definitions
x_coord      dw  0
y_coord      dw  0 
orig_x       dw  0
orig_y       dw  0

CODESEG

proc  draw_x
; This proc has four loops that draw the 'legs' of the X from the intersection point.
     push bp
     mov  bp,sp
     xor  cx,cx
     xor  dx,dx
     mov  cx,[bp+10]           ; x start (how far from the left 0-320)
     mov  dx,[bp+8]            ; y start (how far from the top 0-199)
     mov  [x_coord],cx
     mov  [y_coord],dx
     mov  [orig_x],cx          ; save the intersection point of the X
     mov  [orig_y],dx


     mov  si,[bp+6]            ; leg length (for each 'leg' of the X)
     mov  al,[bp+4]            ; color

;upper left 
     mov  cx,si     ; cx gets the length of the X 'leg'
l1:  push cx        ; loop to draw upper left side (one pixel at a time. x,y - decrease)

     mov  cx,[x_coord]
     mov  dx,[y_coord]
     dec  [x_coord]
     dec  [y_coord]
     ; paint the dot
     mov  bh,0h  
     mov  ah,0ch     
     int  10h
     pop  cx
     loop l1

;lower left        
     ; restore x_coord, y_coord to the intersection original point (orig_x,orig_y) 
     mov  cx,[orig_x]
     mov  dx,[orig_y]
     mov  [x_coord],cx
     mov  [y_coord],dx
     mov  cx,si    ; cx gets the length of the X 'leg'
  
l2:  push cx       ; loop to draw lower left side (one pixel at a time. inc y, dec x)
     mov  cx,[x_coord]
     mov  dx,[y_coord]
     inc  [y_coord]
     dec  [x_coord]
     ; paint the dot
     mov  bh,0h
     mov  ah,0ch  
     int  10h
     pop  cx
     loop l2   

;upper right
     ; restore x_coord, y_coord to the intersection original point (orig_x,orig_y)    
     mov  cx,[orig_x]
     mov  dx,[orig_y]
     mov  [x_coord],cx
     mov  [y_coord],dx 
     mov  cx,si   ;cx gets the length of the X 'leg'

l3:  push cx      ; loop to draw upper right side (one pixel at a time. inc x, dec y)
     mov  cx,[x_coord]
     mov  dx,[y_coord]
     inc  [x_coord]
     dec  [y_coord]
     ; paint the dot
     mov  bh,0h
     mov  ah,0ch  
     int  10h
     pop  cx
     loop l3  

;bottom right 
     ; restore x_coord, y_coord to the intersection original point (orig_x,orig_y)   
     mov  cx,[orig_x]
     mov  dx,[orig_y]
     mov  [x_coord],cx
     mov  [y_coord],dx 
     mov  cx,si   ;cx gets the length of the X 'leg'

l4:  push cx      ;loop to draw lower right side (one pixel at a time. x,y - increase)
     mov  cx,[x_coord]
     mov  dx,[y_coord]
     inc  [x_coord]
     inc  [y_coord]
     ; paint the dot
     mov  bh,0h
     mov  ah,0ch  
     int  10h
     pop  cx
     loop l4              
     pop  bp
     ret  8
endp draw_x 
;------------------------------------------------------------------------------------------

; Sample program to try the drawing

start:
	mov ax, @data
    mov ds, ax 
	;------------------------------------------------------------------------------------------
	; Graphic mode
	mov  ax,13h
	int  10h
	
	; Painting an X. Set (push) column, row,'leg' size and color - in this order.
	push 100
	push 150
	push 7
	push 0Eh
	call draw_x
	
; 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