vjain27
vjain27

Reputation: 3674

what determines the memory model?

Specifically this question is about flat and segmented model in real mode. I am reading a book on assembly which mentions that on DOS the COM files use flat memory model and EXE files use segmented memory model. However I am not understanding what tells DOS which memory model to use. I am asking this question because I am reading about bootloaders.

Upvotes: 4

Views: 367

Answers (3)

David Pointer
David Pointer

Reputation: 935

The COM and EXE executables had their memory requirements in a file header: EXE header and COM (MS-DOS) header. If the program requires < 64KB, use the flat space, if > 64KB, use segmented memory.

Upvotes: 1

Victor Sorokin
Victor Sorokin

Reputation: 12006

There's nothing in DOS that can stop COM file from using segmented memory model, since DOS had no memory management policy enforced on it's applications.

You can read wikipedia entry about COM files, it gives an insight into these old matters.

Upvotes: 1

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81724

COM files used a "flat memory model" in the sense that the segment registers were alll set by DOS when the program was loaded to point to the same segment, and all the code and pointers were, by convention, relative to that one value in the segment registers.

The EXE file format, on the other hand, allows for segments to be loaded at different offsets. DOS wouldn't set the segment registers to default values; that was up to the code itself. 16-bit EXE code is a lot more complex because the code has to manage segment registers.

Nowadays a lot of EXE code more or less ignores segment registers again; 32 or 64-bit registers don't need to be added to a segment register to generate a usable address.

Upvotes: 4

Related Questions