why must we initialize DS And ES registers in MS-D

2019-07-17 05:27发布

问题:

This question already has an answer here:

  • Why doesn't MS-DOS initialize the DS and ES registers? 2 answers

in MS-DOS ,Why the initialization of the DS and ES registers must be done manually by the programmer, although it's operating system responsibility to initialize these registers.

why mustn't we do this for CS and SS registers ? Which feature of MS-dos Leads into this?

回答1:

It's just a choice of the OS designer.

DOS is a minimal OS, so it does the minimum possible. The CS and SS registers must be set. Without CS set for you, your code could not run. SS must be set because DOS uses one stack for everything. Interrupts are using the stack over 30 times per second even while your program is running. (This is why you must turn off interrupts when modifying SS.) The other segments are needed only if your program uses them (and it's certainly possible to write code that doesn't), so DOS isn't concerned.

Actually in DOS versions I remember (and it's been many years so this could be wrong), DS and ES were set equal to CS, which is what you want for very small programs with at most 64k of code+data+stack requirement.



回答2:

EXE files might not have a single or other special segment to default init DS at all, and have multiple static data segments. IOW all globals are FAR.

The first load of DS is then to the segment of the first variable that needs to be loaded.