1.1.2 Operating Systems

With MASM, you can create programs that run under DOS, Windows, or OS/2—or all three, in some cases. For example, ML.EXE can produce executable files that run in any of the target environments, regardless of the programmer's environment. For information on building programs for different environments, see “Building and Running Programs” in PWB's online help.

DOS and OS/2 provide different processing modes. DOS uses the single-process real mode. OS/2 uses the multiple-process protected mode. While OS/2 can also run in real mode, this book assumes it is being used in protected mode.

DOS and OS/2 differ primarily in system access methods, size of addressable memory, and segment selection. Table 1.2 summarizes these differences.

Table 1.2 The DOS and OS/2 Operating Systems


Operating
System

System
Access
Available
Active
Processes

Addressable Memory
Contents of Segment
Register

Word Length

DOS (and OS/2 1.x real mode) Direct to hardware One 1 megabyte Actual address 16 bit
OS/2 1.x protected mode Operating system call Multiple 16 megabytes Segment selectors 16 bit
OS/2 2.x Operating system call Multiple 4 gigabytes Segment selectors 32 bit

DOS

In real-mode programming, you can access system functions by calling DOS, calling the basic input/output system (BIOS), or directly addressing hardware. Access is through DOS interrupt 21h.

Summary: Protected-mode programs cannot directly access hardware ports.

OS/2 1.x

As you can see in Table 1.2, protected mode allows for much larger data structures than real mode, since the addressable memory is extended to 16 megabytes. In protected mode, segment registers contain segment selectors rather than actual segment values. These selectors cannot be calculated by the program; they must be obtained by calling the operating system. Programs that attempt to calculate segment values or to address memory directly do not work.

Note that protected-mode operating systems such as XENIXÒ and OS/2 provide system functions for memory and hardware accesses that would be prohibited with direct processor commands. This software interface permits access without the possibility of corrupting memory or crashing the system.

Protected mode uses privilege levels to maintain system integrity and security. Programs cannot access data or code that is in a higher privilege level. Some instructions that directly access ports or clear interrupts (such as CLI, STI, IN, and OUT) are available at privilege levels normally used only by systems programmers.

OS/2 protected mode enforces the separation of segment values. The segments have selectors that have no relationship to the offset. The operating system combines the segment and offset so that your programs can address up to 16 megabytes of virtual memory in a 16-bit system.

Summary: OS/2 2.x and flat model eliminate segments.

OS/2 2.x

OS/2 2.x uses an unsegmented architecture. (See Section 1.1.3.) It creates a “flat model” in which the entire address space is within one 32-bit segment. Section 2.2.1, “Defining Basic Attributes with .MODEL,” explains how to use the flat model. In a 32-bit system, you can access up to four gigabytes of virtual memory. (The term “virtual memory” means that if the programs running under OS/2 request more memory than is physically available, part of the memory is temporarily swapped out to disk.) Since code, data, and stack are in the same segment, the value of segment registers never needs to change. Internal mechanisms of OS/2 2.x implement protection at a lower level.