;
;       Автор - Александр Белоусов (Mirex)
;
;------------------------------- сег. данных
data_s segment
u      dw      ?
v      dw      ?
d1x    dw      ?
d1y    dw      ?
d2x    dw      ?
d2y    dw      ?
m      dw      ?
n      dw      ?
s      dw      ?
; координаты начала и конца
x1     dw      300
y1     dw      15
x2     dw      0
y2     dw      0
data_s ends
;------------------------------- сег. кода
code_s segment
assume cs:code_s, ds:data_s

;----------- SIGN
;  ax <- число
; -> ax - знак
sign proc
        cmp    ax,0
        jg     @g
        jl     @l
        mov    ax,0
        jmp    @n
@g:
        mov    ax,1
        jmp    @n
@l:
        mov    ax,-1
        jmp    @n
@n:
     ret
sign endp
;------------- ABS
; ax <- число
; -> ax - рез.
abs proc
        cmp    ax,0
        jge    @a
        neg    ax
@a:
    ret
abs endp
;------------- START
start:
        mov    ax,data_s
        mov    ds,ax
        ; гр. режим 320x200x256
        mov    ax,0013h
        int    10h
;---- Линия
        ; u = x2 - x1
        mov    cx,[x2]
        sub    cx,[x1]
        mov    [u],cx
        ; v = y2  - y1
        mov    cx,[y2]
        sub    cx,[y1]
        mov    [v],cx
        ; d1x = sign(u)
        ; d2x = sign(u)
        mov    ax,[u]
        call   sign
        mov    [d1x],ax
        mov    [d2x],ax
        ; d1y = sign(v)
        mov    ax,[v]
        call   sign
        mov    [d1y],ax
        ; d2y = 0
        mov    [d2y],0
        ; m = abs(u)
        mov    ax,[u]
        call   abs
        mov    [m],ax
        ; n = abs(v)
        mov    ax,[v]
        call   abs
        mov    [n],ax
       ; если M<N
        mov    ax,[n]
        cmp    [m],ax
        jg     e1

          mov    [d2x],0
          ; d2y = sign(v)
          mov    ax,[v]
          call   sign
          mov    [d2y],ax
          ; m = abs(v)
          mov    ax,[v]
          call   abs
          mov    [m],ax
          ; n = abs(u)
          mov    ax,[u]
          call   abs
          mov    [n],ax
e1:    ; иначе
        ; s = m / 2
        mov    ax,[m]
        shr    ax,1
        mov    [s],ax

     ;-- цикл от 0 до M --
        mov    cx,[m]
        mov    ax,0A000h
        mov    es,ax
next:
    ; пиксель (x1,y1)
        mov    bx,320
        mov    ax,[y1]
        mul    bx
        add    ax,[x1]
        mov    bx,ax
        mov    byte ptr es:[bx],10

         ; s = s + n
         mov    ax,[n]
         add    [s],ax
         ; если S>M
           mov     ax,[m]
           cmp     [s],ax
           jl      tl
              ; s = s - m
              mov    ax,[m]
              sub    [s],ax
              ; x1 = x1  + d1x
              mov    ax,[d1x]
              add    [x1],ax
              ; y1 = y1  + d1y
              mov    ax,[d1y]
              add    [y1],ax
             jmp eee
          ; иначе
tl:
               ; x1 = x1  + d2x
               mov    ax,[d2x]
               add    [x1],ax
               ; y1 = y1  + d2y
               mov    ax,[d2y]
               add    [y1],ax
eee:
    loop next

;---- end линия

        mov    ah,0
        int    16h
        ; текст. режим
        mov    ax,0003h
        int    10h

        mov    ah,4Ch
        int    21h
code_s ends
       end start