Thursday, June 4, 2009

How the EXE is loaded into main memory for execution - The system Program Loader

Once BIOS hands control over to the OS, you may then request execution of a program.

NOTE: The program can be either .COM or .EXE. A .COM program is useful as a small utility program or as a resident program (one that is installed in memory and is available while other programs run). In real mode, an .EXE program consists of separate code, data and stack segments and is the method used for more serious programs.

When you double click on an .EXE program (when you request the system to load an .EXE program from disk into memory for execution), the System Program Loader performs following steps
  1. Accesses the .EXE program from disk
  2. Constructs a 256-byte (100H) Program Segment Prefix (PSP) on a paragraph boundary in available internal memory (NOTE: PSP is a data structure used in DOS systems to store the state of a program)
  3. Stores the program in memory immediately following PSP
  4. Loads the address of PSP in DS and ES registers
  5. Loads the address of code segment in CS register and sets the IP register to the offset of the first instruction (usually zero) in the code segment
  6. Loads the address of the stack in SS register and sets the SP register to the size of the stack
  7. Transfers control to the program for execution, beginning usually with the first instruction in the code segment

No comments:

Post a Comment