当前位置:网站首页>【汇编语言】从最底层的角度理解“堆栈”
【汇编语言】从最底层的角度理解“堆栈”
2022-04-23 01:59:00 【怪&】
前言
你好啊,我是“ 怪& ”,是一名在校大学生哦。
主页链接:怪&的个人博客主页
️博文主更方向为:课程学习知识、作业题解、期末备考。随着专业的深入会越来越广哦…一起期待。
️一个“不想让我曾没有做好的也成为你的遗憾”的博主。
很高兴与你相遇,一起加油!
一、什么是堆栈?
堆栈是一个特定的存储区或寄存器,它的一端是固定的,另一端是浮动的 。堆这个存储区存入的数据,是一种特殊的数据结构。所有的数据存入或取出,只能在浮动的一端(称栈顶)进行,严格按照“先进后出”的原则存取,位于其中间的元素,必须在其栈上部(后进栈者)诸元素逐个移出后才能取出。在内存储器(随机存储器)中开辟一个区域作为堆栈,叫软件堆栈;用寄存器构成的堆栈,叫硬件堆栈。
简介:
- 一种数据结构
- 堆栈的元素进出遵循:“先进后出”原则
想必大家在使用高级语言,例如:java,c,c++,python等都使用过堆栈,其运行机理大体明白,但细节部分还较模糊。
此篇文章将从《汇编语言》即计算机最底层的角度让你重新认识堆栈。
二、堆栈的前言知识
提及《汇编语言》,不可避免的要讲14个寄存器,如图 (基于8086CPU的哦)

江湖上流传着:“把这14个寄存器学明白,汇编语言就毕业了”的传说。
即然此文讲堆栈,则我们就需要了解:
- SS:堆栈段寄存器
- SP:堆栈指针寄存器组
8086CPU的入栈和出栈操作都是以字(word)为单位进行的。一个字(word)为两个字节(byte)。
任意时刻,SS:SP指向栈顶元素
栈为空时,SS:SP指向栈空间最高地址单元的下一个单元。(因为“任意时刻,SS:SP指向栈顶元素”,所以栈空时不存在栈顶元素,所以SS:SP只能指向栈的最底部单元下面的单元。)
三、堆栈的操作
1、栈的初始化
mov ax,1000H
mov ss,ax ;设置栈的段地址ss=1000H,不能直接向段寄存器SS送入数据,所以用ax中转
mov sp,0010H

2、入栈
mov ax,1234
push ax
Push ax实际是执行了两个操作:
- SP=SP-2
- 将ax内容送入SS:SP指向的内存单元中,SS:SP此时指向新栈顶
存储,遵循“高位存高位,低位存低位”的原则。

3、出栈
Pop bx
pop bx实际是执行了两个操作:
- 将SS:SP指向的内存单元处的数据送入BX中
- SP=SP+2,SS:SP指向当前栈顶下面的单元(新的栈顶)

三、注意事项
- 汇编语言不区分大小写
- 编程时小心栈顶超界:防止“ 栈满继续入栈” 和 “ 栈空继续出栈 ”的超界现象。
- 堆栈空间也是内存空间的一部分
️️️忙碌的敲代码也不要忘了浪漫鸭!

版权声明
本文为[怪&]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_21471309/article/details/124298794
边栏推荐
- Is the availability of proxy IP equal to the efficiency of proxy IP?
- NPM yarn startup error [resolved]
- 配置iptables实现本地端口转发的方法详解
- Nanny level tutorial on building personal home page (II)
- [Dahua cloud native] micro service chapter - service mode of five-star hotels
- [Leetcode每日一题]396. 旋转函数
- Introduction to esp32 Bluetooth controller API
- Question bank and online simulation examination for safety management personnel of hazardous chemical business units in 2022
- What categories do you need to know before using proxy IP?
- What businesses use physical servers?
猜你喜欢

Introduction to micro build low code zero Foundation (lesson 2)

BGP服务器在什么业务场景会被用到?

Why is one plus one equal to two

How to choose a good dial-up server?

如何选择一台好的拨号服务器?

How to classify proxy IP?

Problem solving: dpkg DEB: error: package name has characters that are't lowercase alphanums or '- +‘

About how to import C4d animation into lumion

批处理多个文件合成一个HEX

Introduction to esp32 Bluetooth controller API
随机推荐
Use of j-link RTT
Error in face detection and signature of Tencent cloud interface
2022 crane driver (limited to bridge crane) examination question bank and online simulation examination
Implementation of Base64 encoding / decoding in C language
Is it better to use a physical machine or a virtual machine to build a website?
How to change the size of SVG pictures without width in openlayer
About how to import C4d animation into lumion
Rôles attributs personnels Abréviations
【dpdk】10. Dpdk DNS learning notes
Sqlserver data transfer to MySQL
Problem solving: dpkg DEB: error: package name has characters that are't lowercase alphanums or '- +‘
拨号服务器是什么,有什么用处?
什么是代理IP池,如何构建?
PID精讲
Virtual serial port function of j-link V9 using skills
Analyze the advantages and disadvantages of tunnel proxy IP.
W801/W800-wifi-socket开发(一)-UDP
Longest common subsequence (record path version)
NPM yarn startup error [resolved]
PHP & laravel & master several ways of generating token by API and some precautions (PIT)