home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / tsr / tsrsrc33.zip / RAMFREE.ASM < prev    next >
Assembly Source File  |  1991-11-22  |  3KB  |  86 lines

  1. ;RAMFREE
  2. ;determine amount of available RAM without using CHKDSK
  3. ;Kim Kokkonen, TurboPower Software, 6/85
  4. ;written for MASM or TASM
  5. ;Updated 10/20/91
  6. ;   work for free memory greater than 640K
  7. ;   add size of environment block
  8. ;
  9. Cseg    segment public para
  10.         assume  cs:Cseg, ds:Cseg, es:Cseg
  11.  
  12.         org     100H
  13. ramfree proc    near
  14.  
  15. ;shrink memory available to this program
  16. coment: mov     bx,offset theend
  17.         add     bx,15
  18.         mov     cl,4
  19.         shr     bx,cl                   ;convert bytes to paragraphs
  20.         mov     ah,4AH
  21.         int     21H                     ;DOS SETBLOCK function
  22.  
  23. ;try to allocate the maximum memory
  24.         mov     ah,4AH
  25.         mov     bx,0FFFFH
  26.         int     21H                     ;use SETBLOCK again
  27.                                         ;BX contains paragraphs available
  28.  
  29. ;add size of environment
  30.         mov     ax,ds:[002CH]
  31.         dec     ax
  32.         mov     es,ax
  33.         add     bx,es:[0003H]
  34.  
  35. ;convert paragraphs to a doubleword number of bytes in dx:ax
  36.         mov     ax,bx
  37.         xor     dx,dx
  38.         mov     dl,ah                   ;dl will contain top four bytes of ah
  39.         mov     cl,4
  40.         shr     dx,cl
  41.         shl     ax,cl
  42.  
  43. ;convert doubleword dx:ax to an ASCII string
  44.         mov     di,offset outp$         ;di indexes next output position
  45.         mov     si,offset digits        ;si indexes digit table
  46.  
  47. nextd:  mov     cx,[si]                 ;low word of digit
  48.         add     si,2
  49.         mov     bx,[si]                 ;high word of digit
  50.         add     si,2
  51.         xor     bp,bp                   ;counter for this digit
  52. nextc:  sub     ax,cx
  53.         sbb     dx,bx
  54.         jc      ddone                   ;jump if carry
  55.         inc     bp                      ;else increment counter
  56.         jmp     nextc
  57. ddone:  add     ax,cx                   ;undo last subtraction
  58.         adc     dx,bx
  59.         mov     cx,bp                   ;counter into cx
  60.         cmp     di,offset outp$         ;first output character?
  61.         jne     store                   ;output zeros if not leading
  62.         jcxz    chknc                   ;no output for leading zeros
  63. store:  or      cl,30H                  ;convert count to digit
  64.         mov     [di],cl                 ;store output
  65.         inc     di                      ;next output position
  66. chknc:  cmp     si,offset theend        ;all of table?
  67.         jb      nextd                   ;loop if not
  68.  
  69. ;now output the string and halt
  70.         mov     dx,offset bmess$
  71.         mov     ah,09H
  72.         int     21H                     ;print string
  73.         mov     ax,4C00H
  74.         int     21H
  75.  
  76. ramfree endp
  77.  
  78. ;data area
  79. bmess$  db      'RAM bytes available: '
  80. outp$   db      32,32,32,32,32,32,32,13,10,36           ;ASCII output string
  81. digits  dd      1000000,100000,10000,1000,100,10,1      ;conversion table
  82. theend  label   byte
  83.  
  84. Cseg    ends
  85.         end     ComEnt
  86.