§ Текст программы

На экран выводится линия (0,0)-(319,199),11
1; ------------------------------------------------------------------------------
2; Основная программа
3; ------------------------------------------------------------------------------
4
5        org     100h
6        mov     ax, 0013h
7        int     10h
8        mov     ax, $A000
9        mov     es, ax
10        mov     ax, 0
11        mov     bx, 0
12        mov     cx, 319
13        mov     dx, 199
14        mov     bp, 11
15        call    line
16        ret
17
18; ------------------------------------------------------------------------------
19; Рисование линии
20; x1=ax, y1=bx -> x2=cx, y2=dx; bp-цвет
21; ------------------------------------------------------------------------------
22line:   push    si di
23        mov     si, 1       ; int (si) signx  = x1 < x2 ? 1 : -1;
24        mov     di, 1       ; int (di) signy  = y1 < y2 ? 1 : -1;
25        mov     [.x2], cx
26        mov     [.y2], dx
27        sub     cx, ax      ; int (cx) deltax = |x2 - x1|
28        jge     @f
29        neg     cx
30        neg     si
31@@:     sub     dx, bx      ; int (dx) deltay = |y2 - y1|
32        jge     @f
33        neg     dx
34        neg     di
35@@:     mov     [.sx], si   ; signx
36        mov     [.sy], di   ; signy
37        mov     [.dx], cx   ; deltax = |x2 - x1|
38        mov     [.dy], dx   ; deltay = |y2 - y1|
39        mov     si, cx      ; error = deltax - deltay
40        sub     si, dx
41        mov     dx, bp
42.ps:    cmp     ax, 320     ; ax=[0..319], bx=[0..119]
43        jnb     @f
44        cmp     bx, 200
45        jnb     @f
46        imul    di, bx, 320 ; PSET (ax, bx)
47        add     di, ax
48        mov     [es: di], dl
49@@:     cmp     ax, [.x2]   ; while ((x1 != x2) || (y1 != y2))
50        jne     @f
51        cmp     bx, [.y2]
52        jne     @f
53        pop     di si
54        ret
55@@:     mov     cx, si      ; error2 = 2*error
56        add     cx, cx
57        cmp     cx, [.dx]   ; if (error2 - deltax < 0):
58        jg      @f
59        add     si, [.dx]   ; error += deltax; y1 += signy
60        add     bx, [.sy]
61@@:     add     cx, [.dy]   ; if (error2 + deltay > 0):
62        jle     .ps
63        sub     si, [.dy]   ; error -= deltay; x1 += signx
64        add     ax, [.sx]
65        jmp     .ps
66; ~~~~~~~~~~~~~~~~~~~
67.sx:    dw      0
68.sy:    dw      0
69.dx:    dw      0
70.dy:    dw      0
71.x2:    dw      0
72.y2:    dw      0