为什么我的堆栈指针仅在16的倍数递增? [英] Why is my stack pointer only incrementing in multiples of 16?

查看:334
本文介绍了为什么我的堆栈指针仅在16的倍数递增?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的C code

Using the following C code

void func() {
  int a=1,b=2,c=3;
}

使用 GCC编译-O -S -O- myfile.c文件我得到的输出

    .file   "myfile.c"
    .intel_syntax noprefix
    .text
.globl func
    .type   func, @function
func:
    push    ebp
    mov ebp, esp
    sub esp, 16
    mov DWORD PTR [ebp-4], 1
    mov DWORD PTR [ebp-8], 2
    mov DWORD PTR [ebp-12], 3
    mov DWORD PTR [ebp-16], 4
    mov DWORD PTR [ebp-20], 5
    leave
    ret
    .size   func, .-func
    .ident  "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5"
    .section    .note.GNU-stack,"",@progbits

下面我预计第三行后 FUNC:子ESP,12 而不是子ESP,16 。我打了不同数量的函数自动变量,发现它生长在16个字节为单位。为什么会这样?这是否会发生在所有平台上,或者是特定于平台的?

Here I would expect the third line after func: to be sub esp,12 instead of sub esp,16. I played with different numbers of automatic variables in the function and found that it grows in increments of 16 bytes. Why does this happen? Does this happen on all platforms, or is it platform specific?

我目前正在运行的Intel处理器的Mac OSX与通过一个Ubuntu(32位)编译使用GCC VirtualBox的客人。

I'm currently running an Intel Mac with OSX, compiling through an Ubuntu (32-bit) VirtualBox guest using GCC.

推荐答案

手册页,(黑体重点煤矿):

From GCC man page, (bold emphasis mine):

-m preferred堆栈边界= NUM​​

试图保持一致上调至NUM字节边界2堆栈边界。如果 -m preferred堆栈边界没有指定,默认为4(16字节或128位)

Attempt to keep the stack boundary aligned to a 2 raised to num byte boundary. If -mpreferred-stack-boundary is not specified, the default is 4 (16 bytes or 128 bits).

这篇关于为什么我的堆栈指针仅在16的倍数递增?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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