86能推/弹出少于4个字节? [英] x86 Can push/pop be less than 4 bytes?

查看:98
本文介绍了86能推/弹出少于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?

该指南可以在这里找到,如果有人想查看:
<一href=\"http://www.cs.virginia.edu/~evans/cs216/guides/x86.html\">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.)

这篇关于86能推/弹出少于4个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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