和esp,0xfffffff0 [英] and esp, 0xfffffff0

查看:114
本文介绍了和esp,0xfffffff0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不完全理解下面带有注释的行.我在SO和gcc手册上阅读了几篇文章,并了解到它是用于堆栈地址对齐的,但无法理解它是如何做到的.代码如下所示:

I don't entirely understand the line with comment in it below. I read a few posts on SO and in the gcc manual and learned that it is for stack address alignment but fail to understand how it does so. The code is show below:

(gdb) disas main
Dump of assembler code for function main:
   0x08048414 <+0>: push   ebp
   0x08048415 <+1>: mov    ebp,esp
   0x08048417 <+3>: and    esp,0xfffffff0 ; why??
   0x0804841a <+6>: sub    esp,0x10
   0x0804841d <+9>: mov    DWORD PTR [esp],0x8048510
   0x08048424 <+16>:    call   0x8048320 <puts@plt>
   0x08048429 <+21>:    mov    DWORD PTR [esp],0x8048520
   0x08048430 <+28>:    call   0x8048330 <system@plt>
   0x08048435 <+33>:    leave
   0x08048436 <+34>:    ret
End of assembler dump.

代码是在Linux上使用gcc(版本4.6.3)生成的.谢谢.

The code was generated using gcc (version 4.6.3) on linux. Thanks.

推荐答案

and esp, 0xfffffff0在堆栈指针和常量之间进行按位与运算,并将结果存储回堆栈指针中.

and esp, 0xfffffff0 does a bitwise AND between the stack pointer and a constant, and stores the result back in the stack pointer.

选择该常数,以使其低四位为零.因此,AND操作会将结果中的这些位设置为零,而esp的其他位保持不变.这样可以将堆栈指针向下舍入到最接近的16的倍数.

The constant is chosen so that its low four bits are zero. Therefore the AND operation will set these bits to zero in the result, and leave the other bits of esp intact. This has the effect of rounding the stack pointer down to the nearest multiple of 16.

这篇关于和esp,0xfffffff0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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