What About The Stack?

This lesson addresses how segmentation works in the stack with the help of an example.

We'll cover the following

Thus far, we’ve left out one important component of the address space: the stack. The stack has been relocated to the physical address 28KB in the diagram above, but with one critical difference: it grows backwards (i.e., towards lower addresses). In physical memory, it “starts” at 28KBAlthough we say, for simplicity, that the stack “starts” at 28KB, this value is actually the byte just below the location of the backward growing region; the first valid byte is actually 28KB minus 1. In contrast, forward-growing regions start at the address of the first byte of the segment. We take this approach because it makes the math to compute the physical address straightforward: the physical address is just the base plus the negative offset. and grows back to 26KB, corresponding to virtual addresses 16KB to 14KB; translation must proceed differently.

The first thing we need is a little extra hardware support. Instead of just base and bounds values, the hardware also needs to know which way the segment grows (a bit, for example, that is set to 11 when the segment grows in the positive direction, and 00 for negative). Our updated view of what the hardware tracks is seen in the figure below:

Get hands-on with 1400+ tech skills courses.