Basics memory

1. Memory basics

Here Insert Picture Description

2. What is memory, what role

Hardware memory is used to store data. Before the program execution need to be placed in memory in order to be processed by the CPU.

Question: In a multiprogramming environment, the system may have multiple applications concurrently, which means the data will need to put more programs in memory. So, how to distinguish between the various procedures of data on what is it?
Program: to addressable memory storage unit

Starting memory address 0, each address corresponding to one memory cell

Here Insert Picture Description

There is also a memory of a "small room", each small room is a "memory cell"
if the computer "byte addressing", each memory cell size is 1 byte, i.e.. IB, i.e., 8 bits
If the 16-bit computer word length "by addressing the word", the size of each memory cell of a word: the size of each word is 16 bits

3. Several commonly used number of units

A mobile phone / computer has 4GB of memory, what does this mean?

The memory means may store 4x2 ^ 30 bytes. If it is byte-addressable, then, it is a 30-th power of 2 ^ 32 = "small room" 4 * 2 of
so many "small room", 2 ^ 32 addresses the need to identify eleven, so address 32 binary bits needed to represent (-10 ^ 32 to 2)

Here Insert Picture Description

4. The logical address physical address vs

Four quarters go on a trip together, school number four tail number are 0, 1, 3.
When you live Hotel to arrange the four connecting rooms room number. Four people ascending order of the number of check-school room. Such as No. 0. 1. 2. 3 students were moved into room No. 5,6,7,8.
Four numbers 0. 1. 2.3 is actually a "relative position", while their stay in the room number is an "absolute position."
Just know 0 students lived in a house number N of the room, then M No. students room number must be N + M.
that is, as long as know each student's "relative position" and "starting room number", you will be able to calculate the "absolute position" all students

指令中的地址也可以采用这种思想。编译时产生的指令只关心“相对地址”,实际放入内存中时再想办法根据起始位置得到“绝对地址”。

Eg:编译时只需确定变量x存放的相对地址是100 ( 也就是说相对于进程在内存中的起始地址而言的地址)。CPU想要找到x在内存中的实际存放位置,只需要用进程的起始地址+100即可。

相对地址又称逻辑地址,绝对地址又称物理地址。

5. 从写程序到程序运行

Here Insert Picture Description
编译:由编译程序将用户源代码编译成若干个目标模块(编译就是把高级语言翻译为机器语言)
链接:由链接程序将编译后形成的一组目标模块,以及所需库函数链接在一起,形成一个完整的装入模块
装入(装载) :由装入程序将装入模块装入内存运行

6. 装入的三种方式

绝对装入:

绝对装入:在编译时,如果知道程序将放到内存中的哪个位置,编译程序将产生绝对地址的目标代码。装入程序按照装入模块中的地址,将程序和数据装入内存。
Eg:如果知道装入模块要从地址为100的地方开始存放。

Here Insert Picture Description

绝对装入只适用于单道程序环境。

程序中使用的绝对地址,可在编译或汇编时给出,也可由程序员直接赋予。通常情况下都是编译或汇编时再转换为绝对地址。

静态重定位

静态重定位:又称可重定位装入。编译、链接后的装入模块的地址都是从0开始的,指令中使用的地址、数据存放的地址都是相对于起始地址而言的逻辑地址。可根据内存的当前情况,将装入模块装入到内存的适当位置。装入时对地址进行“重定位”,将逻辑地址变换为物理地址(地址变换是在装入时一次完成的)。

Here Insert Picture Description

静态重定位的特点是在一个作业装入内存时,必须分配其要求的全部内存空间,如果没有足够的内存,就不能装入该作业。作业一旦进入内存后,在运行期间就不能再移动,也不能再申请内存空间。

Dynamic relocation
dynamic relocation: also known as dynamic run into fashion. Compile, link load module address are starting from zero. After the loader module is loaded into memory, and will not immediately logical address into a physical address, but the address translation program really want to postpone execution only . So after all of the addresses are still loaded into memory it is a logical address. This approach requires a relocation register support.

Here Insert Picture Description

Allow dynamic relocation procedures moved in memory.

Relocation Register: loaded storage module stored starting position
and may assign a program to a discontinuous storage area; it is just part of the code is loaded prior to running the program can be put into operation, and during the program run, in accordance with application dynamically allocate memory: easy to share the program segment can provide a much larger memory space than the address space of the user.

7. Links of three ways

Links of three ways:

  1. Static links: Before running the program, the first of each object modules and libraries they need connector into a complete executable file (load module), then no longer open.
    2. Dynamic Link Load: each of the target module into memory, the side links, side links loaded manner.
    3. Run-time dynamic linking: The target module when needed during program execution, it fishes link. The advantage is easy to modify and update, to facilitate sharing of the target module.

Here Insert Picture Description

8. Summary

Here Insert Picture Description

Published 168 original articles · won praise 1 · views 2964

Guess you like

Origin blog.csdn.net/yrx420909/article/details/104475874