Given a segment table, how do you translate the logical address (1, 500)?
Look up segment 1, compare the offset with its limit, and add the offset to its base. If the offset is not below the limit the hardware traps. With limit 400 here, (1, 500) is invalid; (0, 500) maps to 1900.
Explain it simply
A segmented logical address is a pair (segment number, offset). The segment table has a base (where the segment starts in RAM) and a limit (its length) for each segment.
Rule: if offset < limit, physical = base + offset; otherwise trap with a segmentation fault.
| Segment | Base | Limit |
|---|---|---|
| 0 | 1400 | 1000 |
| 1 | 6300 | 400 |
| 2 | 4300 | 400 |
Example
Translate three addresses:
- (0, 500): limit is 1000 and 500 < 1000, so physical = 1400 + 500 = 1900.
- (1, 399): limit is 400 and 399 < 400, so physical = 6300 + 399 = 6699.
- (1, 500): limit is 400 and 500 >= 400, so this is invalid. The hardware traps to the OS, which usually kills the process.
Note that offset 400 in segment 1 is also invalid: valid offsets run from 0 to limit - 1, which is 0 to 399.
The same check catches a buffer overflow that runs past the end of a segment, which is why such a bug shows up as "segmentation fault" on Linux.
What to say in the interview
"I look up the segment's base and limit. If the offset is less than the limit, physical is base plus offset; otherwise it is a trap. So (0, 500) is 1900, and (1, 500) fails because segment 1 is only 400 long."
Common mistakes
- Using offset <= limit. The last valid offset is limit - 1.