home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_asm / test / test.asm next >
Encoding:
Assembly Source File  |  1990-12-08  |  10.3 KB  |  289 lines

  1. ; TEST.ASM
  2. ; (c) 1990 by Roger A. Krupski
  3.  
  4.         page    ,132
  5.  
  6. bufsiz  equ     1024*32         ;32k test buffer
  7.  
  8. data    STRUC
  9. handle  dw      ?               ;handle
  10. time    dw      ?               ;save time
  11. numbuf  db      5 dup (?)       ;output number buffer
  12. source  db      256 dup (?)     ;source filename
  13. param   db      256 dup (?)     ;time parameter
  14. total   dw      ?               ;parsed megabytes
  15. buffer  db      bufsiz dup (?)  ;read data buffer
  16. dsiz    db      ?               ;total data size
  17. data    ENDS
  18.  
  19. code    SEGMENT                 ;define CODE segment
  20.         ASSUME  cs:code,ds:code,es:code,ss:code
  21.         ORG     0100h           ;.COM starts here
  22.  
  23. entry:  cld                     ;insure autoincrement
  24.         sub     sp,dsiz         ;reserve data area
  25.         mov     bp,sp           ;bp points to data area
  26.  
  27.         lea     di,[bp+0]       ;point to data area
  28.         xor     al,al           ;clear al
  29.         mov     cx,dsiz         ;byte count
  30. rep     stosb                   ;clear data area
  31.  
  32.         mov     si,81h          ;point to PSP command line
  33.  
  34.         call    skip            ;skip space(s)
  35.         lea     di,[bp+source]  ;point to data area
  36.         call    copy            ;get filename
  37.  
  38.         call    skip            ;skip space(s)
  39.         lea     di,[bp+param]   ;point to data area
  40.         call    copy            ;get megabytes
  41.  
  42.         lea     si,[bp+param]   ;point to number parameter
  43.  
  44. parse:  lodsb                   ;get a character
  45.         cmp     al,0            ;end of line?
  46.         je      cont            ;yes, continue
  47.         cmp     al,'0'          ;valid?
  48.         jb      error3          ;no
  49.         cmp     al,'9'          ;valid?
  50.         ja      error3          ;no
  51.         sub     al,'0'          ;yes, normalize
  52.  
  53.         push    ax              ;save parsed number
  54.  
  55.         mov     al,byte ptr [bp+total] ;get current accumulator
  56.         mov     ah,10           ;load multiply factor
  57.         mul     ah              ;multiply al by ah
  58.         jc      error3          ;exit if overflow
  59.         mov     byte ptr [bp+total],al ;store new number
  60.         pop     ax              ;get parsed number
  61.         add     al,byte ptr [bp+total] ;add to accumulator
  62.         jc      error3          ;exit if overflow
  63.         mov     byte ptr [bp+total],al ;store new total
  64.         jmp     parse           ;get more
  65.  
  66. error3: mov     cx,siz5         ;size of message
  67.         lea     dx,msg5         ;point to message
  68.         call    print           ;print it
  69.         jmp     exit            ;and leave
  70.  
  71. cont:   lea     dx,[bp+source]  ;point to filename
  72.         mov     ax,3d00h        ;dos "open", read-only mode
  73.         int     21h             ;call DOS
  74.         jnc     ok1             ;go if ok
  75.  
  76.         mov     cx,siz1         ;size of message
  77.         lea     dx,msg1         ;point to message
  78.         call    print           ;print error message
  79.         jmp     exit            ;and leave
  80.  
  81. ok1:    mov     [bp+handle],ax  ;save handle
  82.  
  83.         mov     cx,siz6         ;message size
  84.         lea     dx,msg6         ;point to message
  85.         call    print           ;print it
  86.  
  87.         call    getime          ;get time
  88.         mov     [bp+time],dx    ;save start time
  89.  
  90.         mov     cx,[bp+total]   ;times to do loop
  91.         cmp     cx,0            ;bad number?
  92.         je      error3          ;yes, exit
  93.  
  94.         mov     ax,cx           ;copy megabytes to ax
  95.         mov     dx,32           ;32*32K=1 meg
  96.         mul     dx              ;multiply ax by dx
  97.         mov     cx,ax           ;copy new number to cx
  98.  
  99. speed:  call    read            ;read 32k
  100.         jc      error2          ;exit if error
  101.         loop    speed           ;go again
  102.  
  103.         call    getime          ;get ending time
  104.         mov     ax,[bp+time]    ;get start time
  105.         sub     dx,ax           ;subtract start from end
  106.         jns     ok              ;go if not looped around
  107.  
  108.         add     dx,60*60        ;correct negative time
  109.  
  110. ok:     push    dx              ;save test time
  111.         mov     cx,2            ;2 bytes
  112.         lea     dx,msg1         ;point to cr/lf
  113.         call    print           ;print a cr/lf
  114.  
  115.         mov     dx,[bp+total]   ;get test time
  116.         call    ascii           ;convert time to ascii
  117.         call    numout          ;print test time
  118.  
  119.         mov     cx,siz3         ;message size
  120.         lea     dx,msg3         ;point to message
  121.         call    print           ;print it
  122.  
  123.         pop     dx              ;get test seconds
  124.         call    ascii           ;convert seconds to ascii
  125.         call    numout          ;print number
  126.  
  127.         mov     cx,siz4         ;message size
  128.         lea     dx,msg4         ;point to message
  129.         call    print           ;print it
  130.         jmp     exit            ;exit to dos
  131.  
  132. error2: mov     cx,siz2         ;size of message
  133.         lea     dx,msg2         ;point to message
  134.         call    print           ;print it
  135.         jmp     exit            ;and leave
  136.  
  137.  
  138. ascii:  mov     al,"0"          ;load ascii 00
  139.         mov     cx,5            ;number of ascii places
  140.         push    cx              ;save count
  141.         lea     di,[bp+numbuf]  ;point to number buffer
  142. rep     stosb                   ;store ascii zero
  143.  
  144.         lea     si,nums         ;point to number field
  145.         lea     di,[bp+numbuf]  ;point to number buffer
  146.  
  147.         pop     cx              ;get loop counter
  148.  
  149. loop1:  sub     dx,[si]         ;subtract 10's place
  150.         js      loop2           ;exit if done
  151.         mov     al,[di]         ;get ascii number
  152.         inc     al              ;bump it
  153.         mov     [di],al         ;store it back
  154.         jmp     loop1           ;go again
  155.  
  156. loop2:  add     dx,[si]         ;add number back in
  157.         add     si,2            ;bump si
  158.         inc     di              ;bump di
  159.         loop    loop1           ;do next number
  160.         ret                     ;return
  161.  
  162.  
  163. numout: lea     si,[bp+numbuf]  ;point to number buffer
  164.         mov     dx,si           ;copy to dx
  165.         mov     cx,5            ;max bytes to write
  166. num2:   cmp     cx,1            ;last zero?
  167.         je      num3            ;yes, keep it
  168.         lodsb                   ;get a byte from buffer
  169.         cmp     al,"0"          ;leading zero?
  170.         jne     num3            ;no, print it
  171.         inc     dx              ;yes, point to next
  172.         loop    num2            ;go again
  173. num3:   jmp     print           ;print & return
  174.  
  175.  
  176. read:   push    ax              ;
  177.         push    bx              ;
  178.         push    cx              ;
  179.         push    dx              ;save registers
  180.  
  181.         lea     dx,[bp+buffer]  ;point to buffer
  182.         mov     bx,[bp+handle]  ;get file handle
  183.         mov     ah,3fh          ;dos "read"
  184.         mov     cx,bufsiz       ;get bytes to read
  185.         int     21h             ;call dos
  186.         jc      err             ;error, exit
  187.  
  188.         cmp     ax,bufsiz       ;file big enough?
  189.         je      okay            ;yes
  190.         stc                     ;no, set carry=error
  191.         jmp     err             ;and exit
  192.  
  193. okay:   mov     cx,0            ;offset 0
  194.         mov     dx,0            ;offset 0
  195.         mov     al,0            ;reset file pointer
  196.         mov     ah,42h          ;dos "seek"
  197.         mov     bx,[bp+handle]  ;get handle
  198.         int     21h             ;call dos
  199.  
  200. err:    pop     dx              ;
  201.         pop     cx              ;
  202.         pop     bx              ;
  203.         pop     ax              ;restore registers
  204.         ret                     ;return
  205.  
  206. getime: mov     ah,2ch          ;dos "get time"
  207.         int     21h             ;call dos
  208.         xor     ax,ax           ;clear ax
  209.         push    dx              ;save dx
  210.         mov     al,cl           ;copy minutes into al
  211.         mov     dx,60           ;seconds per minute
  212.         mul     dx              ;multiply ax by dx
  213.         pop     dx              ;restore seconds
  214.         xor     dl,dl           ;drop centiseconds
  215.         xchg    dh,dl           ;swap seconds and centiseconds
  216.         add     dx,ax           ;add minutes to seconds
  217.         ret                     ;dx=absolute seconds, return
  218.  
  219. exit:   mov     bx,[bp+handle]  ;get file handle
  220.         cmp     bx,0            ;no file opened?
  221.         je      exit2           ;no, leave
  222.         mov     ah,3eh          ;dos "close file"
  223.         int     21h             ;close file
  224. exit2:  add     sp,dsiz         ;de-allocate data area
  225.         mov     ax,4c00h        ;dos "terminate"
  226.         int     21h             ;exit to dos
  227.  
  228. skip:   lodsb                   ;get a byte
  229.         cmp     al," "          ;leading space?
  230.         je      skip            ;yes, skip it
  231.         dec     si              ;no, fix si
  232.         ret                     ;return
  233.  
  234. copy:   lodsb                   ;get a byte
  235.         cmp     al," "          ;space?
  236.         je      copy3           ;yes, exit
  237.         cmp     al,0dh          ;end of line?
  238.         je      copy3           ;yes, exit
  239.         cmp     al,"a"          ;lowercase?
  240.         jb      copy2           ;no, keep it
  241.         cmp     al,"z"          ;lowercase?
  242.         ja      copy2           ;no, keep it
  243.         xor     al,20h          ;yes, flip case bit
  244. copy2:  stosb                   ;no, store byte
  245.         jmp     copy            ;continue
  246. copy3:  dec     si              ;fix si
  247.         ret                     ;return
  248.  
  249. print:  mov     ah,40h          ;dos "write"
  250.         mov     bx,1            ;standard out
  251.         int     21h             ;call dos
  252.         ret                     ;return
  253.  
  254. nums    dw      10000
  255.         dw      1000
  256.         dw      100
  257.         dw      10
  258.         dw      1
  259.  
  260. msg1    db      13,10
  261.         db      "Unable to open file."
  262.         db      13,10
  263. siz1    equ     $-msg1
  264.  
  265. msg2    db      13,10
  266.         db      "Test file must be 32768 bytes or larger."
  267.         db      13,10
  268. siz2    equ     $-msg2
  269.  
  270. msg3    db      " megabyte(s) in "
  271. siz3    equ     $-msg3
  272.  
  273. msg4    db      " second(s)."
  274.         db      13,10
  275. siz4    equ     $-msg4
  276.  
  277. msg5    db      13,10
  278.         db      "Parameter error: Must be from 1 to 255 megabytes."
  279.         db      13,10
  280. siz5    equ     $-msg5
  281.  
  282. msg6    db      13,10
  283.         db      "Timing, please wait..."
  284.         db      13,10
  285. siz6    equ     $-msg6
  286.  
  287. code    ENDS
  288.         END     entry
  289.