The Segment Table: To map a 2D logical address to a 1D physical address, the system uses a segment table. Each entry in this table contains a Base (the starting physical address) and a Limit (the length of the segment).
Address Translation Logic: When a CPU generates a logical address , the hardware uses as an index into the segment table. It first checks if the offset is valid by verifying that . If this condition is met, the physical address is calculated as .
Hardware Registers: The Segment Table Base Register (STBR) points to the segment table's location in memory, while the Segment Table Length Register (STLR) indicates the number of segments used by a program. This ensures that a segment index is within the legal range of the table.
| Feature | Segmentation | Paging |
|---|---|---|
| View | User/Logical view | System/Physical view |
| Size | Variable length | Fixed-size blocks (pages) |
| Fragmentation | External fragmentation | Internal fragmentation |
| Address | ||
| Sharing | Easier (logical units) | More complex (fixed boundaries) |
The Boundary Check: Always verify the offset against the limit before calculating the physical address. In exam problems, a common trick is to provide an offset that is equal to or greater than the Limit; in such cases, the answer is a segmentation fault or trap, not a physical address.
Address Calculation: Remember the formula . Ensure you are adding the offset to the base address of the correct segment index provided in the logical address pair.
Fragmentation Identification: If a question asks about the downside of segmentation, focus on external fragmentation. Be prepared to explain how 'compaction' can be used to relocate segments and consolidate free memory into one large block.
Sanity Check: A physical address must always fall within the range defined by . If your calculated address is outside this range, re-check your segment index and offset logic.