What is the difference between a logical address and a physical address?
A logical (virtual) address is what the program generates; a physical address is the real location in RAM. The Memory Management Unit translates one into the other at run time.
Explain it simply
A logical address is like a seat number printed on your exam hall ticket ("row 3, seat 5"), relative to that hall. A physical address is the exact room and building on the campus map. The invigilator (the MMU) converts one into the other.
- Logical address: generated by the CPU while a program runs. Every process thinks its addresses start from 0.
- Physical address: the actual cell in main memory.
- MMU: hardware that maps logical to physical on every memory access.
This gives each process its own private view of memory and lets the OS place a process anywhere in RAM.
Example
The simplest scheme uses a base (relocation) register and a limit register.
Process loaded at physical address 14000 with limit 3000:
- Logical address 346: 346 < 3000, so physical = 14000 + 346 = 14346.
- Logical address 2999: physical = 14000 + 2999 = 16999.
- Logical address 3500: 3500 >= 3000, so the hardware raises a trap and the OS stops the process. This is a segmentation fault.
If the OS moves the process to physical 50000, only the base register changes. The program's logical addresses stay exactly the same, so no program code needs fixing.
What to say in the interview
"Logical addresses are generated by the CPU and are relative to the process; physical addresses are real RAM locations. The MMU translates them at run time, using base and limit registers or page tables. That gives protection and lets the OS relocate processes freely."
Common mistakes
- Saying the compiler assigns physical addresses. With run-time binding, only the MMU does.