0
$\begingroup$

I have been trying to understand the logical and physical address of some data/instruction the logical address is a address generated by the CPU during a execution cycle.So if I write this code

int a = 0;
printf("%d",&a);

what will be printed is the logical address right?So everything from the OS which is running in the computer to a simple program know only the logical address.

$\endgroup$

3 Answers 3

2
$\begingroup$

The OS has to "know" the correspondence between physical and logical addresses, because it's responsible for configuring the Memory Management Unit to map between them, and some part of the OS kernel has to start up in a memory region where logical and physical addresses are identical in order to be able to do that mapping.

Other than that, you're correct, user programs and most of the OS exclusively use logical addresses, and unless you're a low-level kernel developer, you don't need to consider physical addresses at all.

$\endgroup$
2
  • $\begingroup$ Is the memory location of the MMU in every computer at a specific physical address? $\endgroup$
    – Cerise
    Oct 19, 2023 at 15:07
  • $\begingroup$ I'm a little fuzzy on the low-level details. For something like x86 and x64 systems, where there's a device I/O address space separate from memory space, I would guess the MMU is accessed via specific addresses there. The MMU starts up in a known default state that gives the kernel someplace to start from. The kernel sets up the mapping tables in memory and gives instructions to the MMU to look there. $\endgroup$ Oct 19, 2023 at 15:43
2
$\begingroup$

Every time your computer executes an instruction, the address of that instruction is a logical address. Every time a computer instruction access data, the address of the data is a logical address.

There will be some table that describe at which physical address the data belonging to some logical address is stored. Or it isn't stored at any physical address at all, but somewhere on the hard disk, so when you try to execute an instruction or read data, your program gets interrupted, the operating system finds a bit of unused physical memory, reads the data from the hard drive, puts it into that unused memory, then updates the table to reflect where the data is know, and continues your program. OR the table contains information telling your program that it isn't allowed to access data at this logical address, and your program crashes.

Well, there isn't one table, but every process has its own table. So when you switch from process A to process B, A might have data for logical address 12345678 stored at the physical address X, while process B will have completely different data at logical address 12345678 stored at a totally different physical address Y.

The tricky thing is to get the whole thing started. When your computer is turned on, some things happen through the processor's hardware, and then the computer will start executing code at some address X. At this point there is likely no translation between logical and physical addresses turned on yet (because that's too complicated to do using hardware only), so things will be set up so that at this point physical and logical addresses are still the same, and the very first code that the processor executes will likely try to find out which memory chips you have installed in your computer, then it will set up the very first translation table which it can do because it knows what physical memory is available, and then translation gets turned on.

$\endgroup$
0
0
$\begingroup$

Physical address is the precise location of data in computer memory and logical address is a virtual address that a computer program uses to access memory. While newer processors seamlessly handle both physical and logical addresses, older ones like the Intel 8080/8085 directly generates physical addresses. It doesn't have a separate Memory Management Unit (MMU) or support virtual memory.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.