Difference between Virtual and Physical Address
The addresses identify a location in the memory where the actual code resides in the system in the operating system. We store the data in the memory at different locations with addresses to access the data again whenever required in the future. There are two types of addresses used for memory in the operating system, i.e., the physical address and logical address.
The logical address is a virtual address viewed by the user. The user can't view the physical address directly. The logical address is used as a reference to access the physical address. The fundamental difference between logical and physical addresses is that the CPU generates the logical address during program execution. In contrast, the physical address refers to a location in the memory unit.
What is a Logical Address?
A logical address is an address that is generated by the CPU during program execution. The logical address is a virtual address as it does not exist physically, and therefore, it is also known as a Virtual Address. This address is used as a reference to access the physical memory location by CPU. The term Logical Address Space is used to set all logical addresses generated from a program's perspective.
A logical address usually ranges from zero to maximum (max). The user program that generates the logical address assumes that the process runs on locations between 0 and max. This logical address (generated by CPU) combines with the base address generated by the MMU to form the physical address. The hardware device called Memory-Management Unit is used for mapping logical addresses to their corresponding physical address.
What is a Physical Address?
The physical address identifies the physical location of required data in memory. The user never directly deals with the physical address but can access it by its corresponding logical address. The user program generates the logical address and thinks it is running in it, but the program needs physical memory for its execution. Therefore, the logical address must be mapped to the physical address by MMU before they are used. The Physical Address Space is used for all physical addresses corresponding to the logical addresses in a logical address space.
Difference between Logical and Physical Address
The basic difference between Logical and physical addresses is that The CPU generates a logical address from a program's perspective. In contrast, the physical address is a location that exists in the memory unit. Logical Address Space is the set of all logical addresses generated by the CPU for a program. In contrast, all physical addresses mapped to corresponding logical addresses are called Physical Address Space. The logical address does not exist physically in the memory, whereas a physical address is a location in the memory that can be accessed physically.
Identical logical addresses are generated by Compile-time and Load time address binding methods, whereas they differ in the run-time address binding method. The CPU generates the logical address while the program is running, whereas the physical address is computed by the Memory Management Unit (MMU). There are some other differences between the logical and physical addresses, and let's discuss them with the help of the below comparison table.
Mapping Virtual Addresses to Physical Addresses
Memory consists of large array addresses. It is the responsibility of the CPU to fetch the instruction address from the program counter. These instructions may cause loading or storage to a specific memory address.
Address binding is the process of mapping from one address space to another address space. Logical addresses are generated by the CPU during execution, whereas physical address refers to the location in a physical memory unit (the one loaded into memory). Note that users deal only with logical addresses. The MMU translates the logical address. The output of this process is the appropriate physical address of the data in RAM. An address binding can be done in three different ways:
What is Memory Management Unit (MMU)
The run-time mapping between the virtual and physical addresses is done by a hardware device known as MMU. The operating system will handle the processes and move the processes between disk and memory in memory management. It keeps track of available and used memory. The Memory Management Unit is a combination of these two registers,