www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/19/02:06:10

From: lsantil AT calstatela DOT edu
Date: Mon, 18 May 1998 23:00:58 -0700 (PDT)
Message-Id: <199805190600.XAA16785@neptune.calstatela.edu>
To: djgpp AT delorie DOT com
Subject: Re: How much memory installed?

If you would have looked a little harder thru the mail archive search tool,
you would have found something very similar to this I as I asked the same
question a few months back.  It's  actually a pretty useful little utility
--for being so brief--if for some reason you deleted mem.exe from the dos
dir.  Easy C code w/ comments.
-----------------------------------------
#include <stdio.h>
#include <pc.h>

int GetInstalledMemory(void)
{
  unsigned BaseMemory;
  unsigned ExpandedMemory;
  unsigned ExtendedMemory;

  /*
     Gets the amount of Conventional Mem from CMOS up to 640K
   */
  outportb(0x70,0x15);
  BaseMemory = inportb(0x71);
  outportb(0x70,0x16);
  BaseMemory += inportb(0x71) << 8;

  /*
     Gets the amount of XMS Mem from CMOS
   */
  outportb(0x70,0x17);
  ExtendedMemory = inportb(0x71);
  outportb(0x70,0x18);
  ExtendedMemory += inportb(0x71) << 8;

  /*
     Return 384K of EMS Mem if XMS Mem is available
     By Default, if you have XMS, then you can't have
     384K gap in between Conventional Mem & XMS
   */
  ExpandedMemory = ExtendedMemory ? 384 : 0;

  return BaseMemory + ExpandedMemory + ExtendedMemory;
}

int main(void)
{
  printf("\n\nYou have %U Bytes of Memory on your System or\n"
         "You have %U KiloBytes of Memory on your System or\n"
         "You have %U MegaBytes of Memory on your System\n\n",
          GetInstalledMemory()*1024,
          GetInstalledMemory(),
          GetInstalledMemory()/1024);
  return 0;
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019