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