Segmentation — segment table, protection
WHAT is a segment?
The key contrast: in paging all blocks are the same fixed size and the split is invisible to the programmer. In segmentation blocks are different sizes and visible/meaningful to the programmer.
HOW the segment table works (derive the translation)
We need to turn a logical pair into a real physical address. Let's build the machinery from scratch.
Step 1 — Where does segment live in physical memory? Each segment is contiguous, so we only need its starting physical address. Call it the base .
Step 2 — How big is segment ? Because segments vary in length, we must store each segment's limit (length) to stop a program reading past its end.
So per segment we store two numbers: . The table of all these pairs is the segment table. Register STBR (Segment Table Base Register) points to the table; STLR (Segment Table Length Register) says how many entries are valid.
Step 3 — The translation formula

Protection — the real payoff
Each segment-table entry is extended:
| Field | Meaning |
|---|---|
| base | physical start address |
| limit | length (bounds check) |
| R/W/X bits | read / write / execute permissions |
| valid bit | is this segment present/legal? |
Worked Examples
Common Mistakes (Steel-manned)
Flashcards
What two parts make up a segmentation logical address?
What two fields are the minimum per segment-table entry?
Write the address-translation rule for .
Why is the bounds check strict (, not )?
Which register points to the segment table, and which gives its length?
How does segmentation enable safe code sharing?
What protection bits live in a segment entry?
Why does a write to a R/X code segment trap even if the offset is in bounds?
What fragmentation type does pure segmentation suffer?
Segmentation vs paging — who decides block size?
Recall Feynman: explain to a 12-year-old
Imagine your school stuff is in labeled boxes: one "Homework" box, one "Lunch" box, one "Games" box. To find something you say "Box: Games, item 3" instead of memorizing one giant number. The teacher (OS) keeps a list saying where each box sits on the shelf (base) and how big it is (limit). If you ask for item 50 from a box that only has 10 things, the teacher stops you — that's a segmentation fault. And the "Games" box might be look-only (no writing) — try to scribble in it and you get blocked. That label-per-box idea is segmentation, and the box rules are protection.
Connections
- Paging — page table, TLB — fixed-size counterpart; combine into Segmented Paging.
- Memory Management — base & limit registers — segmentation = many base/limit pairs.
- External vs Internal Fragmentation — segmentation → external; paging → internal.
- Address Translation & MMU — hardware performing .
- Shared Libraries & Dynamic Linking — built on shared read-only segments.
- Protection & Memory Safety — R/W/X bits, segmentation fault traps.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, segmentation ka core idea ye hai ki ek program ek single blob nahi hota — usme alag-alag logical pieces hote hain: code, stack, heap, ek array, ek library. Har piece ko hum ek segment bolte hain. Isliye har address do parts ka hota hai: — s matlab kaunsa segment, aur d matlab us segment ke andar kitna offset (displacement). Programmer ki soch ke hisaab se ye natural hai, kyunki tum sochte ho "math wale segment ka function", na ki ek raw address number.
Ab translation kaise hota hai? OS ek segment table rakhta hai jisme har segment ke liye do cheezein store hoti hain — base (physical memory me kahan se start hota hai) aur limit (segment kitna lamba hai). Jab CPU ko milta hai, pehle wo check karta hai d < limit. Agar offset limit se bada ya barabar hai, toh segmentation fault — kyunki tum apne segment ke bahar jaa rahe ho. Agar theek hai, toh physical address . Bas itna simple, lekin yahi do-step (bounds check, phir base add) puri kahani hai.
Protection yahin sabse mast feature hai. Har segment-table entry me R/W/X bits bhi hote hain. Code segment ko sirf Read/Execute do, Write mat do — toh agar koi galti se ya hack karke code ke upar likhne ki koshish kare, hardware turant protection fault maar dega, chahe offset bounds ke andar hi kyun na ho. Aur sharing ka faida: do processes same code segment ke base/limit ko point kar sakte hain (sirf R/X ke saath) — ek hi copy RAM me, dono safely use karte hain. Isliye shared libraries elegant ban gayi.
Ek important yaad rakhne wali baat: bounds check strict < hota hai, <= nahi — kyunki offsets 0 se start hote hain, toh valid offsets sirf 0 se limit-1 tak. Aur ek galat-fehmi clear kar lo: segmentation me external fragmentation hoti hai (variable-size holes), internal nahi — paging ulta hai.