Address binding and the MMU
Address binding and the MMU
Recorded by Dr. Krithika L.B. Slot m4-address-binding
How the addresses in a program become real memory addresses — at compile, load or run time — and how the MMU and base/limit registers relocate and protect each process.
By the end of this session you should be able to:
Every process from Module 2 needs its instructions and data in main memory — the only large storage the CPU can address directly. With many processes in memory at once (multiprogramming), the OS must answer three questions: where does each process go, how are its addresses translated, and how is it protected from the others?
The simplest protection uses two registers loaded by the kernel on every context switch: a base register (smallest legal physical address) and a limit register (size of the range). The hardware checks every user-mode address:
If either test fails → trap to the OS (addressing error). Only the kernel can load base and limit — they are privileged instructions (Session 1.3).
A program refers to memory symbolically (count, main). Along the way to execution, these addresses are
bound to real memory addresses. Binding can happen at three stages:
The programmer writes count = count + 1; — a symbolic address.
If the compiler knows where the process will live, it generates absolute code (e.g. count at 74014). If the start location changes, the program must be recompiled. Example: MS-DOS .COM programs.
Otherwise the compiler generates relocatable code (“14 bytes from the start of this module”). The loader binds to absolute addresses when the program is loaded. If the start changes, just reload.
If a process can be moved during execution (e.g. swapped out and back to a different place), binding is delayed until run time. Needs hardware support — the MMU. All general-purpose OSes use this.
The full path: source → compiler → object module → linker (+ other modules, libraries) → load module → loader (+ dynamically linked libraries) → in-memory binary image.
Generated by the CPU — what the program sees. The set of all of them is the logical address space.
Seen by the memory unit — what is loaded into the memory-address register. The set is the physical address space.
With compile-time and load-time binding the two are identical; with execution-time binding they differ, and the Memory-Management Unit (MMU) maps logical to physical at run time. The simplest MMU adds a relocation register (the base register) to every address:
Relocation register = 14000, limit = 3000. The program issues logical address 346.
Check 346 < 3000 ✔ → physical address = 14000 + 346 = 14346.
Logical address 3500 → 3500 ≥ limit → trap. The program only ever sees addresses 0 – 2999; it never knows it lives at 14000.
libc.so / .dll is shared by all processes, and updating the library updates every program. Try
ldd /bin/ls.A process can be swapped temporarily out of memory to a backing store (fast disk) and brought back later — the medium-term scheduler of Session 2.1. Swapping lets the total memory of all processes exceed physical memory, but moving a whole process is slow: a 100 MB process at 50 MB/s takes 2 s each way. Modern systems swap individual pages instead (Session 4.5), and mobile OSes usually terminate background apps rather than swap.
Address binding and the MMU
Recorded by Dr. Krithika L.B. Slot m4-address-binding
Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.
Answer each question in your own words first, then reveal the model answer.
Revealed 0100 → 5100. 1300 ≥ 1200 → trap (addressing error).
Execution-time binding, with MMU hardware.
Otherwise a user program could change them and access any memory, defeating protection.
One shared copy of a library serves all processes (less memory and disk), and library updates apply without recompiling programs.
With an MMU we can put a process anywhere. But where exactly, when memory is a patchwork of free holes? Next: contiguous allocation and placement algorithms.
Continue to 4.2 — Contiguous memory allocation and fragmentation →