Thread: INT 15 to return memory size

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    23

    INT 15 to return memory size

    I am writing a program for DOS to return the extended memory size but it is not working properly. The code I have is below
    Code:
    	_asm 
          {
            xor ax,ax       /* Clear accumulator*/
            mov ah,0x88      /* move hex 88 into AH*/
            nop
    	nop
    	nop
    	int 15h
    	mov memory, ax
    	}
    		
    	printf("\nThe extended memory size is %d (0x%X).\n", memory, memory);
    This is returning a value of 0, but my ram is 512MB.

    What am I doing wrong? Does it have to do with the registers being 16 bit?

    Also I will need to get the base memory size as well, but that is next on the list after I can figure this part out.

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Probably register size limitation. If your memory is 512MB, then the number of 1K blocks, which is what the interrupt returns, would be 524288. That would require an integer of at least 19 bits to represent.

    According to one place I found, "works only on 80286 and 80386 machines". My guess is the amount of RAM during those machines was never anticipated to go that high.

    http://www.htl-steyr.ac.at/~morg/pci...s/inte7dps.htm
    Last edited by nonoob; 06-14-2010 at 02:45 PM.

  3. #3
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    You'll probably need to look at function 0xe820.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > What am I doing wrong? Does it have to do with the registers being 16 bit?
    And your compiler being over 20 years old, and that the OS for which it was written never knew that more than 1MB of memory ever existed.

    Backwards compatibility only stretches so far. You've reached the end of the road - time to upgrade.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Take a look at Detecting Memory (x86) - OSDev Wiki. It lists ah=88 as one of the backups with many issues. Like kennedy said, use eax=e820. The link I gave has an example of how to use the output of eax=e820.

  6. #6
    Registered User
    Join Date
    Jun 2010
    Posts
    23
    ok i am using INT 15 ax=0xe820 now but i am having issues with the upper 16 bits of the ax register. i looked at the DOS.h file but it doesn't have anyway to write to the eax register, and if i try something like:

    Code:
    _asm
    {
    move eax, 0x0000e820
    }
    my compiler doesn't like "eax", i can only use ax

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Like I said - powerpoint presentation using stone chisels.

    When are you going to realise you have the wrong tool for the job?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Jun 2010
    Posts
    23
    I don't want to do this, it is an assignment

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well I hope you mention some of the difficulties you overcame in your report.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    I think it's mov.

  11. #11
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by nonoob View Post
    I think it's mov.
    Wow. I've read that line numerous times. Read yours too. Never saw the difference in the move and the mov. I had to read yours like 5 times to figure out the difference.

    Isn't it amazing that we get so that we read the real thing even though what is printed is wrong.

    Good catch nonoob!

  12. #12
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Hehe, maybe you still had some Motorola 68000 cobwebs in your brain.

  13. #13
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    WTF is up with those nops and the xor ax,ax before you move 88h into ah?(I just now took the time to actually look at the code, before I just noticed the fact OP is using ah=88.)
    Code:
    xor ax,ax
    mov ah,*
    Just use "mov ax,8800h"
    Code:
    nop
    nop
    nop
    ...
    WHY!?

    Just kidding, but really, none of that is needed. I realize there's no need for so-called optimization, but there's also no reason to literally waste clock cycles . nops take up space in the cache and cause extra fetching for no reason in this case.

    One important thing to note about eax=e820 is that even though e820 can fit in ax, it's expected that the top word of eax be cleared. I doubt it would cause your computer to explode, but it's better to be safe.

  14. #14
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Salem View Post
    > What am I doing wrong? Does it have to do with the registers being 16 bit?
    And your compiler being over 20 years old, and that the OS for which it was written never knew that more than 1MB of memory ever existed.

    Backwards compatibility only stretches so far. You've reached the end of the road - time to upgrade.
    Every time you boot an Intel computer, it starts up in 16-bit mode and the OS boot loader has to use a BIOS request exactly like this to figure out how much RAM is available. Day-to-day programmers don't have to do things like this any more but it's by no means outdated. We all still have BIOSes and they are all still 16-bit.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  15. #15
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Intel doesn't make computers .

    > the OS for which it was written never knew that more than 1MB of memory ever existed.
    MS-DOS 5.0 introduced HIMEM.SYS, which is the driver used to enable the A20 line extending the addressable memory to 16MB . Talking about backwards compatibility, it's stupid how much we have retained from the time of DOS. The old way of enabling the A20 was through a pin in the keyboard controller! This way is still maintained and used today(although there is a BIOS int to do it). The A20 originated from an attempt in the 80286 to keep compatibility with the 8086. Such a waste of time, huh?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why doesn't this example work for me?
    By xixpsychoxix in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2009, 08:25 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Alegro closes out on me
    By campsoup1988 in forum C++ Programming
    Replies: 8
    Last Post: 04-03-2006, 10:40 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM