PRODUCT : Borland C++ NUMBER : 1335 VERSION : 3.x OS : ALL DATE : October 26, 1993 PAGE : 1/4 TITLE : Determining the amount of available extended memory. Determining the amount of extended memory present ================================================= The documented INT 15h, 88h may not always accurately return the amount of memory present on a PC. This is a result of the method used by memory managers and other applications accessing/using extended. When extended memory is allocated an application will usually hook the int 15h and monitor calls to function 88H; the new interrupt handler will only return the memory that it is not use by the application. Most Memory Managers will hook interrupt 15h and return a modified result when function 88h is called. This makes this API unreliable. The correct and most direct method to get the amount of extended memory installed on a given machine is to go thru the CMOS. The CMOS is organized into registers that can be querried by performing successive in and out instructions to ports 70H and 71H. An out is done to port 70H to tell the CMOS which register will be read from or written to. A read or write can then be done at port 71H to accomplish the desired read or write. The code provided below determines the amount of extended memory using the INT 15h API and reading from CMOS directly. Running the code on machines with memory managers ( eg. HIMEM.SYS ) will result in disimilar values. ; ------------; ; GETEXT.ASM ; ; ------------; .model large, c .code locals ; *************************************************** ; * function to get the amount of extended memory * ; *************************************************** COMMENT @ - Pass a 1 to the function to retrieve the information thru INT 15h,88h. - Pass a 0 to the function to retrieve the information thru CMOS registers. PRODUCT : Borland C++ NUMBER : 1335 VERSION : 3.x OS : ALL DATE : October 26, 1993 PAGE : 2/4 TITLE : Determing the amount of available extended memory. - Returns amount of extended memory ( in K ) found in AX. ENDCOMMENT @ getext proc par:word ; get passed word of the stack in cx register mov cx, par ; check which method to check for extended memory or cx, cx jz @cmos_check; @int15check: ; Use the int 15h,88h function mov ax, 8800h int 15h jmp @exit @cmos_check: ; Use the cmos data registers mov al, 30h ; get least significant byte out 70h, al in al, 71h mov cl, al mov al, 31h ; get most significant byte out 70h, al in al, 71h mov ch, al ; return extended memory in AX mov ax, cx @exit: ret endp public getext end PRODUCT : Borland C++ NUMBER : 1335 VERSION : 3.x OS : ALL DATE : October 26, 1993 PAGE : 3/4 TITLE : Determing the amount of available extended memory. ;------------; ; EXTGET.CPP ; ;------------; #include #ifdef __cplusplus extern "C" { #endif unsigned getext( short type ); #ifdef __cplusplus } #endif int main( void ) { unsigned kilos; kilos = getext( 1 ); printf( "Total extended memory thru' int 15h is %uK\n", kilos ); kilos = getext( 0 ); printf("Total extended memory thru' cmos %uK\n", kilos ); return( 0 ); } To build an .EXE from the two files provided above, use the folliwing command: BCC -ml -v EXTGET.CPP GETEXT.ASM ( The above command will compiler EXTGET.CPP, invoke TASM.EXE to assemble GETEXT.ASM and then call TLINK.EXE to create an excutable ). PRODUCT : Borland C++ NUMBER : 1335 VERSION : 3.x OS : ALL DATE : October 26, 1993 PAGE : 4/4 TITLE : Determing the amount of available extended memory. DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.