I am learning the . In Chapter16: Segementation, I got a promble that confuesed me for a while. The book said:
In this example, assume we wish to access virtual address 15KB, which should map to physical address 27KB. Our virtual address, in binary form, thus looks like this: 11 1100 0000 0000 (hex 0x3C00). The hardware uses the top two bits (11) to designate the segment, but then we are left with an offset of 3KB. To obtain the correct negative offset, we must subtract the maximum segment size from 3KB: in this example, a segment can be 4KB, and thus the correct negative offset is 3KB minus 4KB which equals -1KB. We simply add the negative offset (-1KB) to the base (28KB) to arrive at the correct physical address: 27KB.
enter image description here
My question is this: in the picture, the size of the stack segment is 2KB for both virtual address and physical memory. Why does the maximum segment size become 4KB through calculation? Another question is, based on the calculated offset of 3KB, why do we need to subtract 4KB to get the correct offset? Is it because a 12-bit binary number cannot represent a negative number, so we have to use -4KB to get a negative offset?
Black Hsiao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.