home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol10n19.zip / NUMFILES.ASM < prev    next >
Assembly Source File  |  1991-10-15  |  4KB  |  80 lines

  1. ;****************************************************************************
  2. ; NUMFILES reports the number of SFT entries created to record the state
  3. ; of open files, and thus the setting of FILES= in CONFIG.SYS.  To create
  4. ; NUMFILES.COM from NUMFILES.ASM, type
  5. ;
  6. ;       MASM NUMFILES;
  7. ;       LINK NUMFILES;
  8. ;       EXE2BIN NUMFILES NUMFILES.COM
  9. ;
  10. ; NUMFILES 1.0 Copyright (c) 1991 Jeff Prosise
  11. ; First published in PC Magazine, November 12, 1991
  12. ;****************************************************************************
  13.  
  14. code            segment
  15.                 assume  cs:code,ds:code
  16.                 org     100h
  17. begin:          jmp     short main
  18.  
  19. msg             db      "FILES=$"
  20. crlf            db      13,10,"$"
  21.  
  22. ;****************************************************************************
  23. ; Procedure MAIN
  24. ;****************************************************************************
  25.  
  26. main            proc    near
  27.                 xor     cx,cx                   ;Zero SFT entry count
  28.                 mov     ah,52h                  ;Get address of DOS's List
  29.                 int     21h                     ;  of Lists
  30.                 mov     di,es:[bx+4]            ;Place address of first SFT
  31.                 mov     es,es:[bx+6]            ;  header in ES:DI
  32. ;
  33. ; Walk the chain of SFT headers counting the number of entries in each block.
  34. ;
  35. mloop:          add     cx,es:[di+4]            ;Add number of SFT entries
  36.                                                 ;  in this block
  37.                 mov     bx,es:[di]              ;Place address of next SFT
  38.                 mov     es,es:[di+2]            ;  header in ES:DI and loop
  39.                 mov     di,bx                   ;  if the offset address
  40.                 cmp     di,0FFFFh               ;  isn't equal to FFFFh
  41.                 jne     mloop
  42. ;
  43. ; Display SFT count and exit.
  44. ;
  45.                 mov     ah,09h                  ;Output "FILES="
  46.                 mov     dx,offset msg
  47.                 int     21h
  48.                 mov     ax,cx                   ;Transfer count to AX
  49.                 call    bin2asc                 ;Print it
  50.                 mov     ah,09h                  ;Output a carriage return/
  51.                 mov     dx,offset crlf          ;  line feed pair
  52.                 int     21h
  53.                 mov     ax,4C00h                ;Exit with ERRORLEVEL=0
  54.                 int     21h
  55. main            endp
  56.  
  57. ;****************************************************************************
  58. ; BIN2ASC converts a binary value in AX to ASCII form and displays it.
  59. ;****************************************************************************
  60.  
  61. bin2asc         proc    near
  62.                 mov     bx,10                   ;Initialize divisor word and
  63.                 xor     cx,cx                   ;  digit counter
  64. b2a1:           inc     cx                      ;Increment digit count
  65.                 xor     dx,dx                   ;Divide by 10
  66.                 div     bx
  67.                 push    dx                      ;Save remainder on stack
  68.                 or      ax,ax                   ;Loop until quotient is zero
  69.                 jnz     b2a1
  70. b2a2:           pop     dx                      ;Retrieve a digit from stack
  71.                 add     dl,30h                  ;Convert it to ASCII
  72.                 mov     ah,2                    ;Display it
  73.                 int     21h
  74.                 loop    b2a2                    ;Loop until done
  75.                 ret
  76. bin2asc         endp
  77.  
  78. code            ends
  79.                 end     begin
  80.