Search code examples
assemblymemory-managementx86-16dosgnu-assembler

How can I get an extra segment in DOS?


I'd like to write a little DOS program (my first one) and I'm a little bit inexperienced.

For the program, I need more than 64 kilobytes of (conventional) memory. How can I get extra memory? Ideally, I'd like to have two extra 64k blocks of memory for the program. Can I just start to write data somewhere into the address space or do I need to request extra memory?


Solution

  • Under DOS, yes, you can just start using another segment of memory. There is an important caution, however!

    Have a look at a memory map for the version of DOS that you are using. You want to be sure that you aren't selecting a region of memory that is actually reserved for another purpose. Here is one from Dr. Dobb's Journal:

    Address (Hex)                 Memory Usage
    
    0000:0000                Interupt vector table
    0040:0000                ROM BIOS data area
    0050:0000                DOS parameter area
    0070:0000                IBMBIO.COM / IO.SYS *
    mmmm:mmmm                BMDOS.COM / MSDOS.SYS *
    mmmm:mmmm                CONFIG.SYS - specified information
                             (device drivers and internal buffers
    mmmm:mmmm                Resident COMMAND.COM
    mmmm:mmmm                Master environment
    mmmm:mmmm                Environment block #1
    mmmm:mmmm                Application program #1
         .                        .      .                        .      .                        .
    mmmm.mmmm                Environment block #n
    mmmm:mmmm                Application #n
    xxxx:xxxx                Transient COMMAND.COM
    A000:0000                Video buffers and ROM
    FFFF:000F                Top of 8086 / 88 address space
    

    The "official" memory allocation mechanism is through memory control blocks (MCB) and the DOS interrupt 0x21 using 0x48 to allocate and 0x49 to free memory. A good discussion of this can be found in this Microsoft support document.

    For documentation on the interrupt approach, you might look here.