Memory Address Changing


- **Physical address space** - Starting at address 0, going to address MAXsys
- **Logical address space** - Starting at address 0, going to address MAXprog
**CPU(code) execute instructions by logical address**
> **relative address** is an example of logical addres**s**


### Address Generation
![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fd35ce2bf-0ec6-44eb-a128-e63e6089a756%2FUntitled.png?table=block&id=2d6934fd-f96f-4c0d-a731-09f64ece4df1&cache=v2)
until linking, code has relative address and after loading to memory, it has physical address
→ Hardware for Address Translation (For adequate performance) ← dynamically “relocated”
- **Base (also called Relocation) Register **- used for validation in CPU (either limit R)
- **Limit Register -** size of program

## Linking
combining various pieces of code and data into a single file that can be loaded into memory
<details><summary>

Linker’s tasks</summary>

1. **Symbol resolution** : each **global symbol** in an object file is bound to a **unique definition**
2. **Relocation** : the physical **memory address for each symbol is determined **and where **references **to those objects are modified **either**
</details>

<details><summary>

kind of linker</summary>

1. static linker(`linkage editor’) - Object modules combine while Compile time 
2. dynamic linker - Useful with language libraries (no duplicated copies) - done in Load time or  Run time
</details>


### Shared library
- Static libraries disadvantages - Potential for duplicating- **ex. libc.a**
- automatically occur when executable - also occur by user code dlopen() - routines can be shared by multiple processes **ex. ****[libc.so](http://libc.so)**




