当前位置:网站首页>Memory and stack related concepts
Memory and stack related concepts
2022-07-06 05:46:00 【qq_ twenty-nine million five hundred and sixty-six thousand six】
Memory
The smallest storage unit in a computer is bytes , Memory is no exception , Each byte acts as a storage unit . In this way, the memory is divided into hundreds of millions of memory units , To facilitate the management of these units , The computer has chosen to number each memory unit , When you want to use a memory unit , Just specify the memory unit number ( Memory address ) that will do . In order to number as many addresses as possible , The computer uses a 4 Number of bytes to address memory , This is good for 2^32 Block memory for addressing , Each block is 1byte,2^32 byte = 4Gb, The memory size that can be addressed is 4G size .
Stack
When the program runs, it will not immediately allocate all memory for the program , Will initialize a certain size of memory area to the program , Memory blocks in this memory space can be used by programs , Used to store data in the program . This space is used from memory blocks with large addresses , To see which address memory unit is used by the current stack , stay ESP The current memory location used is recorded in the register , If you add a data , Will be added at this location , then ESP Continue to move forward one position . therefore ESP The current position of the register record , Is the position of the next data insertion . This pointer is called the stack top pointer , The pointer is added with the data (push) And take out (pop) Move . alike ,EBP The address of the beginning of a stack is recorded in , Become a pointer at the bottom of the stack , The address usually does not change , Only in opening up a new stack space , For example, when executing a function call , When you need to re record a new function space for a function , Will change the position of the bottom of the stack . But when changing the pointer at the bottom of the stack , The original position at the bottom of the stack will be put on the stack and saved , It is convenient to restore to the original bottom of the stack in the future .
Stack elevation
We know , In advanced languages , When we execute a function call , Will open up a new stack space , At this point, stack lifting is required , You need to change ESP and EBP Bottom of stack and bottom of stack pointer recorded in register , In this way, the value generated in the function will not affect the original stack space ( The yellow part ) The data of . The right figure shows the result of stack elevation , here push The data will come from 1005 Start adding ,pop Only to 1005 The data of this address , Can't go down any further pop, This will not affect the contents of the metastack .
Stack balance
Stack balancing is actually restoring stack contents , For example, when performing a function operation , Stack up , Open up new space for functions , When function execution ends , The bottom and top pointers should be restored to their original positions .
The brief process is
1. take ESP Value in register , Change to EBP Value , In this way, the top of the stack is at the current bottom of the stack .ESP=1005
2. take EBP Get the value in the memory address pointed to by the register , namely 1000, take EBP The value of the register is changed to this value 1000. such EBP Back to 1000 The location of .
Thus, the stack recovery is completed , Stack balance is achieved
Data width
There are three data widths in assembly language , Respectively
BYTE: One byte wide , Occupy 8 position
WORD: word , Two bytes wide , Occupy 16 position
DOUBLEWORD: Two words , Four byte width , Occupy 32 position .
Large and small end mode
Memory is addressed from small to large , When storing a multi byte data , If the small address of memory stores the high order of multi byte data , It's the big end model . in other words , First get the high bit of the data for storage , Then take the low order storage . For example, a string "abcd",a Is the high order of the data ,d It's low , The memory will take out four consecutive memory spaces to store this string . If this continuous memory is stored in a small address a And then in turn bcd, It's the big end model . If the low order data is stored in the small address , Small end mode .
It is up to the compiler to store the data in big end or small end mode .
add , All registers contain addresses
边栏推荐
- 59. Spiral matrix
- [detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
- What preparations should be made for website server migration?
- Practice sharing: how to safely and quickly migrate from CentOS to openeuler
- (column 22) typical column questions of C language: delete the specified letters in the string.
- Classes and objects (I) detailed explanation of this pointer
- P2802 go home
- Yunxiaoduo software internal test distribution test platform description document
- How to download GB files from Google cloud hard disk
- 授予渔,从0开始搭建一个自己想要的网页
猜你喜欢

Redis message queue
![[JVM] [Chapter 17] [garbage collector]](/img/f4/e6ff0e3edccf23399ec12b7913749a.jpg)
[JVM] [Chapter 17] [garbage collector]
![[Jiudu OJ 08] simple search x](/img/a7/12a00c5d1db2deb064ff5f2e83dc58.jpg)
[Jiudu OJ 08] simple search x

YYGH-11-定时统计

ArcGIS application foundation 4 thematic map making

数字经济破浪而来 ,LTD是权益独立的Web3.0网站?

Clear floating mode

RustDesk 搭建一个自己的远程桌面中继服务器

B站刘二大人-Softmx分类器及MNIST实现-Lecture 9

Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
随机推荐
Zoom through the mouse wheel
Analysis of grammar elements in turtle Library
【云原生】3.1 Kubernetes平台安装KubeSpher
Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
RustDesk 搭建一个自己的远程桌面中继服务器
清除浮动的方式
B站刘二大人-线性回归及梯度下降
How to get list length
Yunxiaoduo software internal test distribution test platform description document
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
[detailed explanation of Huawei machine test] statistics of shooting competition results
进程和线程
How to use PHP string query function
嵌入式面试题(一:进程与线程)
Summary of data sets in intrusion detection field
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...
通讯录管理系统链表实现
03. 开发博客项目之登录