Lesson 2: Memory Mapping

[Previous] [Next]

Computer memory has many functions. Some memory is reserved for particular uses by the processor and, if improperly allocated, will cause problems. Understanding how to identify and manage memory is key to optimizing a computer. In this lesson, you learn how memory is allocated. Later, you will learn how to apply this information and optimize computer memory (in Chapter 15, "Software: MS-DOS and Windows 3.x."

After this lesson, you will be able to:

  • Know how to use hexadecimal numbers.
  • Define the different types of memory access.
  • Optimize memory allocation.

Estimated lesson time: 20 minutes

The Workings of Hexadecimal Code

Chapter 2, "Understanding Electronic Communication," introduced the concept of binary notation. This is how computers count—by setting the value of a two-position switch to either 0 (off) or 1 (on). Ones and zeroes work well when machines are conversing, but that language can be somewhat confusing for computer designers and programmers. To simplify the representation of numbers and notations, designers and programmers use a numbering system called hexadecimal notation (also known simply as hex). This is a numbering system based on 16 instead of 10. Fortunately, computer technicians do not have to be experts in hexadecimal notation. You do, however, need to know how to use the numbering system as it relates to computer memory.

Hexadecimal is used to simplify notation of binary code in much the same way that we sometimes count in 5s or 10s when it is more convenient than working our way through a problem by 1s. You might ask how anyone would find it simpler to count in hex. Well, in dealing with a system that uses 8 bits, addressing counting locations in hex (a system based on eight positions) makes perfect sense.

All address buses and wires within a computer come in some multiple of 4 (8, 16, 20, 24, 32). Because there are 16 different combinations, the 16 unique characters of the base-16 numbering system are a natural choice for computer shorthand when referring to memory locations or a bus address. The following table contrasts binary notation with hex shorthand.

Binary Number Hex Shorthand Binary Number Hex Shorthand
0000 0 1010 A
0001 1 1011 B
0010 2 1100 C
0011 3 1101 D
0100 4 1110 E
0101 5 1111 F
0110 6
0111 7
1000 8
1001 9

Hexadecimal Shorthand

There is no need to say:


To use hex shorthand:

  • Break the 20 digits into 5 sets:

 1011     0110     0110     0010     1101 

  • Give each 4-character set its hex shorthand:

 1011      0110      0110      0010      1101 B         6         6         2         D 

Hex shorthand = B662D

To represent all the possible addresses for the 20-bit address bus, we use 5 hex values (0 to F) that map to their binary equivalents, from all 0s:

 0000     0000     0000     0000     0000 0        0        0        0        0 

to all 1s.

 1111     1111     1111     1111     1111 F        F        F        F        F  

Each of the possible memory locations for the Intel 8088 can be represented by 5-digit hexadecimal values, starting at 00000 and ending at FFFFF.

Memory Allocation

Previously in this chapter, we discussed memory in terms of the chips themselves. In this section, we look at how that memory is allocated for use by the CPU. This is called memory mapping and uses hexadecimal addresses to define ranges of memory.

Run the memory video located in the demos folder on the CD accompanying this book to view a presentation of memory allocation.

The original processors developed by Intel were unable to use more than 1 MB of RAM, and the original IBM PC allowed only the first 640 KB of memory for direct use. MS-DOS applications were written to conform to this limitation. As application requirements grew, programmers needed to optimize the use of memory to make the most of the available space. This 1 MB of memory was divided into two sections. The first 640 KB was reserved for the operating system and applications (designated as conventional memory). The remaining 384 KB of RAM (designated as upper memory) was earmarked for running the computer's own housekeeping needs (BIOS, video RAM, ROM, and so on). Although some early PC clones had firmware that could make direct use of the upper memory block available to programmers, actually doing so would result in hardware and software incompatibility issues (see Figure 7.9)

Figure 7.9 IBM PC/MS-DOS Memory map

Under MS-DOS and Windows 3.x, the 640-KB area must be kept as free as possible for program use. MS-DOS memory optimization ensures that MS-DOS applications have as much of this memory as possible. The MS-DOS limitations no longer apply to Windows 95 in 32-bit mode and newer operating systems. However, they are still an important part of running MS-DOS, Windows 3.x-based programs on older machines or in MS-DOS compatibility mode with the more advanced operating systems.

Types of Memory Access

When we speak of memory in a computer, we are generally speaking of its RAM, because ROM cannot be written to by either the system or applications. Although we have only one source of RAM, under MS-DOS-based operating systems, it is divided into smaller groups depending on how it is used.

Extended Memory Specification (XMS)

RAM above the 1-MB address is called extended memory. With the introduction of the 80286 processor, memory was addressable up to 16 MB. Starting with the 80386DX processor, memory was addressable up to 4 GB. Extended memory is accessed through an extended memory manager (HIMEM.SYS for MS-DOS or a third-party utility such as 386MAX).

Conventional Memory

Conventional memory is the amount of RAM, typically 640 KB, that is addressable by an IBM PC or compatible machine operating in real mode. (Real mode is the only operating mode supported by MS-DOS.) Conventional memory is located in the area between 0 and 640 KB. Without the use of special techniques, conventional memory is the only kind of RAM accessible to MS-DOS programs.

MS-DOS Protected Mode Interface (DPMI)

MS-DOS Protected Mode Interface (DPMI) is a specification that allows multiple applications to access extended memory at the same time and has been endorsed by most memory-manager producers and applications developers. Windows uses the DPMI specification.

Expanded Memory Specification (EMS)

This technique, developed by Lotus/Intel/Microsoft (LIM), uses a 64-KB section of memory (usually in upper memory) to provide a "window" in which data can be written. Once in this area, the data can be transferred to the expanded memory. The memory chips are located on an expansion card installed inside the computer. The data is paged or swapped to and from the CPU through this window (see Figure 7.10).

Figure 7.10 Expanded memory

Expanded memory can provide up to 32 MB of additional memory, and because it is loaded from a 64-KB section, it is below the 1-MB limit and therefore MS-DOS can recognize it.

MS-DOS applications must be specifically written to take advantage of expanded memory. Windows applications do not use expanded memory; 80386 and newer processors can emulate expanded memory by using memory managers such as EMM386.EXE and HIMEM.SYS.

High Memory Area (HMA)

An irregularity was found in the Intel chip architecture that allowed MS-DOS to address the first 64 KB of extended memory on machines with 80286 or higher processors. This special area is called the high memory area. A software driver called an "A20 handler" must be run to allow the processor to access the HMA. MS-DOS uses HIMEM.SYS for this purpose. The only limitation is that HIMEM.SYS can load only a single program into this area. Typically, MS-DOS is loaded into HMA to free conventional memory (see Figure 7.11).

Figure 7.11 High memory area

Protected Mode

Beginning with 80286 processors using an operating system such as OS/2 or Windows, a computer can create "virtual machines," providing all the functionality of a standard computer in real mode but allowing multiple tasks to take place at the same time. This is called protected mode because the processor, memory, and other hardware are "protected" from the software application taking direct control of the system by the operating system, which allocates memory and processor time.

Real Mode

In real mode (MS-DOS), a computer can perform only one operation at a time and an application expects full control of the system. Real mode operates within the MS-DOS 1-MB limitation.

Shadow RAM

Many high-speed expansion boards use shadow RAM to improve the performance of a computer. Shadow RAM rewrites (or shadows) the contents of the ROM BIOS and/or video BIOS into extended RAM (between the 640-KB boundary and 1 MB). This allows systems to operate faster when application software calls any BIOS routines. In some cases, system speed can be increased up to 400 percent (see Figure 7.12).

Figure 7.12 Shadow RAM

Upper Memory Area (UMA)

The upper memory area (UMA), the memory block from 640 KB to 1024 KB, is designated for hardware use, like video RAM, BIOS, and memory-mapped hardware drivers that are loaded into high memory. Refer to Chapter 15, "Software: MS-DOS and Windows 3.x," for details.

Upper Memory Blocks (UMB)

The unused addresses in upper memory, known as upper memory blocks (UMB), can be divided into blocks. These empty blocks have no RAM associated with them and are simply reserved space. This unused space is valuable because, unlike expanded and extended memory, MS-DOS can run programs in UMB.

Virtual Control Program Interface (VCPI)

The memory-management specification, known as Virtual Control Program Interface (VCPI), accesses extended memory for MS-DOS-based applications. It allows only one application to control extended memory and does not support multitasking. Windows is not compatible with the VCPI specification.

Determining Usable Memory

The MS-DOS command MEM (MEM.COM) provides information about the amount and type of memory available (see Figure 7.13). It provides a quick way to determine how all of the different areas in physical memory are being used and the total amount of RAM actually active on the system.

click to view at full size.

Figure 7.13 MEM.COM

Most MS-DOS and many early Windows systems load numerous device drivers and TSR (terminate-and-stay resident) programs using the CONFIG.SYS and AUTOEXEC.BAT routines during the boot cycle. These programs are, by default, loaded into conventional memory, taking up valuable space. Memory management techniques are used to load these device drivers and TSRs into the upper memory, allowing more lower memory to be made available to applications.

To determine which device drivers and TSRs are loaded, use the command:


The "/c" is a classify switch. This determines how much conventional memory a certain real-mode program is using (see Figure 7.14).

click to view at full size.

Figure 7.14 MEM/C

You can also use the Memory button provided with MSD.EXE (Microsoft Diagnostics) to determine the amount and allocation of memory (see Figure 7.15).

click to view at full size.

Figure 7.15 Microsoft Diagnostics

Hexadecimal notation is used by Microsoft Diagnostics. U represents areas of the UMA which are used by TSRs and device drivers.

Lesson Summary

The following points summarize the main elements of this lesson:

  • Hexadecimal notation is used as shorthand for writing binary numbers.
  • Memory is defined in terms of the physical characteristics of the chips and how the memory is allocated for use.
  • The MS-DOS operating system can address only the first 1 MB of memory.
  • Expanded memory was an early method of adding memory to an MS-DOS-based system. It paged, or swapped, 64-KB chunks of data through a window (a 64-KB block of memory in the upper memory area) to an expansion card.
  • Extended memory, used by Windows 3.x and newer systems, allows the addressing of memory above the MS-DOS limit and has virtually replaced expanded memory.
  • Understanding memory allocation and the different memory locations is key to optimizing a computer's memory.
  • The MS-DOS command MEM.COM is a utility that provides information about memory allocation.

Microsoft Corporation - A+ Certification Training Kit
Microsoft Corporation - A+ Certification Training Kit
Year: 2000
Pages: 127

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net