Memory consists of large array of words or arrays, each of which has address associated with it. Now the work of CPU is to fetch instructions from the memory based program counter. Now further these instruction may cause loading or storing to specific memory address.
Address binding is the process of mapping from one address space to another address space. Logical address is address generated by CPU during execution whereas Physical Address refers to location in memory unit(the one that is loaded into memory).Note that user deals with only logical address(Virtual address). The logical address undergoes translation by the MMU or address translation unit in particular. The output of this process is the appropriate physical address or the location of code/data in RAM.
An address binding can be done in three different ways:
Compile Time – If you know that during compile time where process will reside in memory then absolute address is generated i.e physical address is embedded to the executable of the program during compilation. Loading the executable as a process in memory is very fast. But if the generated address space is preoccupied by other process, then the program crashes and it becomes necessary to recompile the program to change the address space.
Load time – If it is not known at the compile time where process will reside then relocatable address will be generated. Loader translates the relocatable address to absolute address. The base address of the process in main memory is added to all logical addresses by the loader to generate absolute address. In this if the base address of the process changes then we need to reload the process again.
Execution time- The instructions are in memory and are being processed by the CPU. Additional memory may be allocated and/or deallocated at this time. This is used if process can be moved from one memory to another during execution(dynamic linking-Linking that is done during load or run time). e.g – Compaction.
MMU(Memory Management Unit)-
The run time mapping between Virtual address and Physical Address is done by hardware device known as MMU.
In memory management, Operating System will handle the processes and moves the processes between disk and memory for execution . It keeps the track of available and used memory.
Instruction-execution cycle Follows steps:
- First instruction is fetched from memory e.g. ADD A,B
- Then these instructions are decoded i.e., Addition of A and B
- And further loading or storing at some particular memory location takes place.
As main memory and registers are built into processor and CPU can access these only.So every instructions should be written in direct access storage
- If CPU access instruction from register then it can be done in one CPU clock cycle as registers are built into CPU.
- If instruction resides in main memory then it will be accessed via memory bus that will take lot of time. So remedy to this add fast memory in between CPU and main memory i.e. adding cache for transaction.
- Now we should insure that process resides in legal address.
- Legal address consists of base register(holds smallest physical address) and limit register(size of range).
Base register = 300040 limit register = 120900 then legal address = (300040+120900)= 420940(inclusive). legal address = base register+ limit register
How processes are mapped from disk to memory
- Usually process resides in disk in form of binary executable file.
- So to execute process it should reside in main memory.
- Process is moved from disk to memory based on memory management in use.
- The processes waits in disk in form of ready queue to acquire memory.
Procedure of mapping of disk and memory
Normal procedure is that process is selected from input queue and loaded in memory. As process executes it accesses data and instructions from memory and as soon as it completes it will release memory and now memory will be available for other processes.
MMU scheme –
- CPU will generate logical address for eg: 346
- MMU will generate relocation register(base register) for eg:14000
- In Memory physical address is located eg:(346+14000= 14346)
Reference and Image Source:
This article is contributed by Vaishali Bhatia.If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Logical and Physical Address in Operating System
- Physical and Logical Data Independence
- Physical and Logical File Systems
- Design Issues in Physical Layer
- Difference between Private and Public IP addresses
- Virtual Memory in Operating System
- Virtual Memory | Questions
- Difference between Virtual memory and Cache memory
- Virtual Machines in Operating System
- Difference between Virtual Machines and Containers
- Types of Virtual Machines
- Importance of Computer Networking
- Protection Ring
- Attribute Closure Algorithm and its Utilization
Improved By : NEERAJ NEGI