先决条件 – 地址绑定方法
地址绑定是程序指令和数据与实际物理内存位置的关联。操作系统中有多种类型的地址绑定。
地址绑定有 3 种类型:
- 编译时地址绑定
- 加载时间地址绑定
- 执行时地址绑定
在这里,我们比较编译时间和执行时间地址绑定如下。
编译时地址绑定:
如果编译器负责执行地址绑定,那么它被称为编译时地址绑定。这种类型的地址绑定将在将程序加载到内存之前完成。编译器需要与操作系统内存管理器交互以执行编译时地址绑定。
执行时间或动态地址绑定:
即使将程序加载到内存中,地址绑定也会被推迟。程序将不断更改内存中的位置,直到程序执行为止。这种类型的地址绑定将由处理器在程序执行时完成。
Compile Time 和 Execution Time 地址绑定的区别:
Compile Time Address Binding | Execution Time Address Binding |
---|---|
Compiler is responsible for the compile time address binding. | Execution time address binding is done by processor. |
It generates logical address (virtual address). | It generates dynamic absolute address. |
Compile time address binding is done before loading the program into memory. | Execution time address binding is done at the time of program execution. |
Instructions are translated into absolute address. | It helps in execution. |
Code is compiled here. | From memory instructions are executed by CPU. |
It works with logical address. | It works with dynamic absolute address. |
It is static address binding. | It is dynamic address binding. |
Compiler interacts with operating system memory manager to perform it. | It is done by processor at the time of program execution. |