软硬件系统编程PPT (22).pdf
存储器管理存储器管理 Storage Management Programs written by users and the data are stored in the form of files in external storage.It must be imported into memory before executing.Importing the program from the hard disk to the internal storage involves the following steps:compilation link object object programprogram executable executable programprogram source source programprogram Note the reason Written in programing languages Written in machine languages of 0 and 1 Processing of user programs Memory Loading Link Object program of machine language Library Library functionfunction Compile 3 The compiled object program modules are connected and assembled together,and then connected with the function library to form a whole.By operating system Questions Where in memory should the program and data be stored?What if the program is too big to be stored in memory?Will the address of a program remain the same after being imported into memory several times?Will different programs disturb each other as they are all imported into memory?5 Import programs from the online external storage(hard disk)into memory Address conversion.Convert the address of the program into that of memory.Storage allocation.Allocate memory space to programs Uniformly manage the hard disk and memory to form the storage system and expand storage capacity Expand storage capacity::to ensure that big programs can execute in small storage Storage protection Protect programs and data zone from being damaged Main functions of storage management Program is a sequence of instructions.The location of each instruction in program is described as address.6 Storage allocation and address conversion 12345H 11H mov ax,59e8h mov cx,5 L1:inc bx add al,bx loop L1 Memory is organized in units.Each unit has the only address in memory.Symbolic addressSymbolic address Physical addressPhysical address Address conversion is the process to match the symbolic address with the physical address in memory.7 Since compiler doesnt know the address of the object program in memory,the logical address of all object programs starts with 0.8 mov ax,59e8h mov cx,5 L1:inc bx add al,bx loop L1 0000H:B8E859H 000BH:B90500 000EH:43H 000FH:0207H 0011H:E2FBH Logical address Compilation Mechanical address 0000H:B8E859H 000BH:B90500 000EH:43H 000FH:0207H 0011H:E2FBH Object program in machine language When loading into memory,the logical address must be transformed into physical address in memory.9 loading B8E859H B90500 43H 0207H E2FBH 10000H 1000BH 1000EH 1000FH 10011H memorymemory Address relocation:the process of transforming logical address of the program into physical address in memory,including:Static relocation,dynamic relocation Dynamic relocation is commonly adopted by modern computers Program relocates during execution,which means the logical address of program is transformed into physical address through hardware address translation mechanism every time before visiting memory units.10 Storage allocation and address conversion 0000H:B8E859H 000BH:B90500 000EH:43H 000FH:0207H 0011H:E2FBH 10000H+000EH B8E859H B90500 43H 0207H E2FBH 10000H 1000BH 1000EH 1000FH 10011H memorymemory Original address when importing into memory Example of address conversion Relative address Relocation address 12 The object module doesnt need to make any changes when loading into main memory.After loading,it can execute normally without being affected by any movements;If a module is composed of several independent object modules,each object module can be loaded into nonadjacent spaces in memory to take full advantage of memory space and share resources.Features of dynamic relocation:Storage protection Generally,computer programs include:System program,user program Purpose of storage protection:Different types of programs are stored in different spaces.Safeguard by ensuring all programs execute independently in their own spaces without disturbing each other.13 System region User region Spaces protection of main memory 14 Storage expansion Objectives of storage expansion:How to execute large programs in smaller memory Methods:Automatic coverage technique“exchange”technique Virtual storage technique Virtual Storage Technique Uniformly manage memory and part of the hard disk to utilize external storage as memory.For users,there seems to have a memory space with sufficient capacity,where they can write programs in this space without worrying the capacity of memory.Virtual Storage memory External storage Storage capacity expansionStorage capacity expansion