Techniques to Find Extended Memory in a Windows DLL

Last reviewed: February 15, 1996
Article ID: Q75682
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

For a Windows-based application to determine the amount of extended memory installed in the machine on which it is running, the extended memory word can be retrieved from the machine's AT Real Time Clock/CMOS RAM. Typically, 80286, 80386 SX, 80386 DX, and i486 based computers store setup information in CMOS. This article details how to access this data.

MORE INFORMATION

The AT Real Time Clock/CMOS RAM is accessed via port 70h, and read from and written to via port 71h. The extended memory word is stored low-order byte first in the CMOS. The first (low order) byte is stored at address 17h, and the second (high order) byte is stored at address 18h.

To read a particular address in the CMOS, write the address to read to port 70h, then retrieve the information from port 71h. Figure 1 contains a code fragment, written in Microsoft C version 6.0 with inline assembly, which shows how to check the CMOS for extended memory size. For compatibility with future versions of Windows, the following code should NOT be placed directly into a Windows-based application. Instead, this code should be placed in a dynamic-link library (DLL), which can be called by applications.

Figure 1. Sample Extended Memory Size Check

   int MemorySize = 0;

    _asm
        {
        xor   ax, ax
        mov   al, 17h
        out   70h, al
        ; jmp   $+3               ; delay not needed in most cases
        in    al, 71h
        mov   MemorySize, ax
        mov   al, 18h
        out   70h, al
        ; jmp   $+3               ; delay not needed in most cases
        in    al, 71h
        xchg  al, ah
        or    MemorySize, ax
        }

     printf("\nExtended Memory size = %u KB\n", MemorySize);

The AT Real Time Clock/CMOS RAM configuration is documented in its entirety in the IBM PC technical reference, on pages 1-56 to 1-68. The information contained in the article was obtained from "The Programmer's PC Source Book," by Thom Hogan, published by Microsoft Press (1988).

Please note that although the BIOS on most machines automatically configures the CMOS entry for extended memory size with the amount of memory the BIOS power-on self-test (POST) routines find in the machine, some BIOS setup programs allow the user to configure the extended memory setting themselves. If the user has not filled in the correct number for the amount of extended memory installed in the machine, the check described in this article will be useless.

WEXTMEM is a file in the Software Library that contains source code for a Windows-based application that reports the amount of extended memory installed in the machine on which the program is run.

Download WEXTMEM.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download WEXTMEM.EXE (size: 20613 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get WEXTMEM.EXE (size: 20613 bytes) 
    


Additional reference words: 3.00 3.10 softlib
KBCategory: kbprg kbfile
KBSubcategory: KrMm


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.