Topic : The VGA Training Program
Author : Grant Smith
Page : << Previous 18  Next >>
Go to page :


                    2   2   3   3
    shl     bx, 1                     2   2   3   3
    shl     bx, 1                     2   2   3   3
    shl     bx, 1                     2   2   3   3
    shl     bx, 1                     2   2   3   3
    shl     bx, 1                     2   2   3   3
    add     dx, bx                    3   2   2   1
    pop     bx                       12   5   4   4
    add     bx, dx                    3   2   2   1
    mov     di, bx                    2   2   2   3
    xor     al,al                     3   2   2   1
    mov     ah, [Col]                 8   5   4   1
    mov     es:[di],ah               10   3   2   1
    pop     es                       12   5   7   3
    pop     ds                       12   5   7   3
  End;                              ---------------
END;                                153  75  76  52 Total ticks


NOTE : Don't take my clock ticks as gospel, I probably got one or two
       wrong.

Right, now for some optimising. Firstly, if you have 286 instructions
turned on, you may replace the 6 shl,1 with shl,6. Secondly, the Pascal
compiler automatically pushes and pops ES, so those two lines may be
removed. DS:[SI] is not altered in this procedure, so we may remove
those too. Also, instead of moving COL into ah, we move it into AL and
call stosb (es:[di]:=al; inc di). Let's have a look at the routine now :


Procedure Putpixel (X,Y : Integer; Col : Byte; where:word);
BEGIN                                 -clock ticks-
  Asm                               8088 286 386 486
    mov     ax,[where]                8   5   4   1
    mov     es,ax                     2   2   2   3
    mov     bx,[X]                    8   5   4   1
    mov     dx,[Y]                    8   5   4   1
    push    bx                       15   3   2   1
    mov     bx, dx                    2   2   2   1
    mov     dh, dl                    2   2   2   1
    xor     dl, dl                    3   2   2   1
    shl     bx, 6                     8  11   3   2
    add     dx, bx                    3   2   2   1
    pop     bx                       12   5   4   4
    add     bx, dx                    3   2   2   1
    mov     di, bx                    2   2   2   3
    mov     al, [Col]                 8   5   4   1
    stosb                            11   3   4   5
  End;                             ----------------
END;                                 95  56  43  27 Total ticks


Now, let us move the value of BX directly into DI, thereby removing a
costly push and pop. The MOV and the XOR of DX can be replaced

Page : << Previous 18  Next >>