13.2 Registers to be saved
---------------------------
Registers to be saved: BP, DI, SI, DS, SS, SP, CS and IP.
BP is used as a pointer to local and function parameters in the stack,
which necessitates saving it.
DI and SI need not be saved if the programmer is aware of the
consequences. DI and SI are often used for indexing arrays as for example:
dog = firehydrant(1,red) + legs[DI];
If DI was not saved in the firehydrant function, the value assigned to
variable dog will most likely be incorrect, since the index for the array
legs was changed. Actually, for all functions to agree closely, the
functions must have a special pointer in the commentary showing that the
contents of DI and/or SI are not saved.
DS points to the data segment, and all operations with global variables
use this value.
SS stores the stack segment and must be saved. SP points to the current
position in the stack and must also be saved.
CS stores the program code segment. All commands are chosen using CS
and IP, consequently these values must be saved. IP, as we know, is the
pointer for the command address, and CS and IP cannot be changed directly
in 8086, 8088, 286, 386, 486 or pentium processors.