Address Binding
- Assigning an address to an instruction or data/variable is known as address binding.
- Thus address binding is a process of generating memory addresses where instructions and data of a program are to be stored.
- The programs are usually stored in any secondary storage device. When a program is run, the computer reads the instruction and loads them in the ready queue. The operating system then selects a process from the ready queue and executes it.
- The entire execution phase of the program consists of three basic phases or steps:
(a) Compilation phase
(b) Loading phase
(c) Run phase or execution phase.
- The source program is converted into a machine readable format by a compiler or assembler. This machine format of source program is called object module.
- A linker combines various object modules that have been compiled or assembled separately into a format known as load module.
- A loader then loads the program into memory for execution. There are three types of loading
(i) Absolute loading. In this, a program is loaded into a specific or fixed location in the memory
(ii) Relocatable loading. It uses relative addressing. The program is loaded at any random location in the memory.
(iii) Dynamic loading. In this scheme, a function is loaded when it is called for the first time In this, a loader does not bind any external reference of an object code until the external reference is used. The binding of instructions and data to memory addresses (i.e. address binding) can be done at any of these three steps : compile time, load time or run time.
1. Compile time binding
- In compile time binding the addresses of data and instructions are resolved at the time of Compilation of program.
- This scheme uses absolute addresses for variables & functions as assembler or compiler generates absolute addresses.
- This type of binding is used for small, simple system.
- The problem with this binding is that if there happens to be a change in the starting location of a process (in memory), then the entire process must be recompiled to generate the absolute addresses again.
2. Load time binding
- In load time binding, the addresses of data and instructions are resolved at the time of loading the program in memory.
- In this case, the compiler or assembler generates relocatable addresses and these are converted to absolute addresses at load time.
- If there is change in the starting address of the program, the program is statically relocated.
- Such a relocation is obtained by adding the addresses used in the program to the content of relocation register i.e. Effective address =Address used by program + contents of relocation register.
3. Run time binding
- It is also known as dynamic binding.
- In this scheme, instructions and data are loaded into the memory at the run time.
- This method permits moving a process from one memory segment to other during run time.
- Such an implementation requires good hardware support.
Logical and physical address space
There are two types of addresses : logical and physical
Logical address
- The address generated by the CPU is known as logical address or virtual address.
- Logical address is the address of an instruction or data as used by the program.
- While writing a program, a programmer refers to with only logical address. Referring physical addresses is not allowed.
Physical Address
- The physical address is an address that is seen by the memory unit.
- Any location in main memory is uniquely identified by an address. Such as address is called physical address.
- Thus, a physical address is the effective memory address of an instruction or data i.e. it is the address obtained after binding of logical address has been done.
- The set of all logical addresses generated by a program is called a logical address space of the process.
- The set of all physical addresses (in the main memory) which the process actually occupies constitute the physical address space of the process.
- Thus, the logical addresses generated by the program are converted into the physical addresses. This process of converting a logical address into physical address in called memory mapping.
- The memory mapping is provided by a hardware device called memory management unit (MMU). Thus, memory management unit is a hardware device that converts a logical address into a physical address.
- Several different methods like paging, segmentation etc. can be used for memory mapping.
The simplest method for memory mapping is to use relocation register and is explained by the following points :
1. The base address of the program is loaded in the relocation register.
2. The physical address of the instruction of a program is calculated by adding the value of the relocation register to the logical address. It means the value in the relocation register is added to every address generated by a user program at the time it is sent to memory.
Thus every address used in the program is relocated as :
Effective address = Address used by program + contents of relocation register
3. For example, the base address of program is 46000 and the logical address of a particular instruction is 442. Thus the corresponding physical address of the instruction is obtained by adding the content of relocation register (base address) to the logical address of the instruction.
Thus, physical address = 46000 + 442 = 46442.
4. Such a relocation is known as dynamic relocation.
Comparison between Logical address and Physical address space
S. No. |
Physical address |
Logical address |
1. | The address generated by the CPU is known as logical address or virtual address. | The physical address is an address that is seen by the memory unit. |
2. | Logical address is the address of an instruction or data as used by the program. While writing a program, a programmer refers to with only logical address. Referring physical addresses is allowed. | Any location in main memory is uniquely identified by an address. Such as address is called physical address. Thus, a physical address is the effective memory address of an instruction or data ie it is the address obtained after binding of logical address has been done. |