SAMPLE: WextMem.exe Finds Extended Memory in a Windows DLL

ID: Q75682


The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1


SUMMARY

WextMem.exe is a file 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.

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 following file is available for download from the Microsoft Download Center. Click the file name below to download the file:

WextMem.exe
For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.

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.

Additional query words:

Keywords : kbfile kbsample kb16bitonly kbKernBase kbMemory
Version : WINDOWS:3.0,3.1
Platform : WINDOWS
Issue type :


Last Reviewed: December 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.