x86 push/pop 可以小于 4 字节吗? [英] x86 Can push/pop be less than 4 bytes?

查看:35
本文介绍了x86 push/pop 可以小于 4 字节吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在阅读弗吉尼亚大学关于 x86 的指南,其中指出推送和弹出堆栈要么删除堆栈,要么添加一个 4 字节数据元素.

Hi I am reading a guide on x86 by the University of Virginia and it states that pushing and popping the stack either removes or adds a 4-byte data element to the stack.

为什么设置为 4 个字节?这可以改变吗,你能通过推送更小的数据元素来节省堆栈上的内存吗?

Why is this set to 4 bytes? Can this be changed, could you save memory on the stack by pushing on smaller data elements?

如果有人想查看该指南,可以在这里找到:http://www.cs.virginia.edu/~evans/cs216/guides/x86.html

The guide can be found here if anyone wishes to view it: http://www.cs.virginia.edu/~evans/cs216/guides/x86.html

推荐答案

简答:是的,16 位或 32 位.而且,对于 x86-64,64 位.

Short answer: Yes, 16 or 32 bits. And, for x86-64, 64 bits.

堆栈的主要原因是从嵌套函数调用返回并保存/恢复寄存器值.它也通常用于传递参数和返回函数结果.除了最小的参数外,这些项在处理器设计上通常具有相同的大小,即指令指针寄存器的大小.对于 8088/8086,它是 16 位.对于 80386 和后续版本,它是 32 位的.因此,在其他大小上操作的堆栈指令几乎没有价值.

The primary reasons for a stack are to return from nested function calls and to save/restore register values. It is also typically used to pass parameters and return function results. Except for the smallest parameters, these items usually have the same size by the design of the processor, namely, the size of the instruction pointer register. For 8088/8086, it is 16-bits. For 80386 and successors, it is 32-bits. Therefore, there is little value in having stack instructions that operate on other sizes.

还有内存总线上数据大小的考虑.检索或存储一个字所花费的时间与处理一个字节所花费的时间相同.(除了 8088,它有 16 位寄存器,但有 8 位数据总线.)对齐也起作用.堆栈应在字边界上对齐,以便每个值都可以作为一个内存操作检索.权衡通常是为了节省时间而不是节省内存.要将一个字节作为参数传递,通常使用一个字.(或者,根据编译器可用的优化,将使用一个字大小的寄存器,完全避免堆栈.)

There is also the consideration of the size of the data on the memory bus. It takes the same amount of time to retrieve or store a word as it does a byte. (Except for 8088 which has 16-bit registers but an 8-bit data bus.) Alignment also comes into play. The stack should be aligned on word boundaries so each value can be retrieved as one memory operation. The trade-off is usually taken to save time over saving memory. To pass one byte as a parameter, one word is usually used. (Or, depending on the optimization available to the compiler, one word-sized register would be used, avoiding the stack altogether.)

这篇关于x86 push/pop 可以小于 4 字节吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆