Tuesday, Aug 22nd

Last update12:59:40 PM GMT

Address Binding

Write e-mail

We all know, any program that needs to be executed, must be brought to main memory and all the instructions that use addresses in a program, must be bound to proper address space in main memory. Address binding is the scheme that does this job. It can be thought as a mapping from one address space to another. We call the two address spaces as : Virtual (or Logical) Address Space and the other as Physical Address Space.

argaiv1864

The mapping of addresses in any program can be done at any of the following three steps: 

  1. Compile Time Binding: If we know before compiling the program where will the program reside in memory, then generating the absolute code of the program is possible. If that location changes then program will need to be compiled again.
  2. Load Time Binding: If we don’t know at compile time, where will the program reside, then we cant generate the absolute code at compile time. So a relocatable code is generated by the compiler. At load time, the relocatable addresses will be mapped to the absolute addresses based on the starting address allocated to the program at the time of loading.
  3. Execution Time Binding: In both the Address Binding techniques described above, by the time program is in execution, the program has the absolute addresses with it, and hence it can directly refer to absolute addresses. That is, logical and physical addresses are same. However,the modern day approach of memory management is based on paging and segmentation and hence the process is moved in and out of the main memory during its execution life. In such case, both the above two approaches cannot be followed. In such case the binding is delayed till run time. Most of the present day OS use this approach and that is where concept of binding of virtual address to physical address come into picture. How does it work?  Read on :-)

The real memory address of any instruction in main memory is what we call as its physical address. But any user program is never allowed to see that address directly. Any user program usually works on logical address. How is it different from a physical address?

Well lets suppose we have a logical address = 246. But when translated to a real (physical address) it will translate to 2000 (value in relocation register) + 246 (offset) = 2246. See figure.

OS

As you can see the above scheme requires some hardware support: a base register to work as a relocation register and a hardware device to manage the above mapping (called Memory Management Unit or MMU).

The above approach works well with the modern day OS where the instructions' address change during the execution as a result of paging and segmentation (We will be taking them on in later articles). Moreover this approach is also associated to memory protection. Each program can be confined to work withing a set of memory addresses. This is done using a limit register. Each address generated by CPU is checked against the value in limit register to ensure that it doesnt point to an out of bounds address (or an invalid one). In absence of this its possible that program may result in an address that it should not be referring to.

Share this post



Add comment

Please refrain from using slang or abusive language in the comments.
To avoid waiting for your comment to be published after being reviewed, please log in as a registered user.


Security code
Refresh

Web Hosting