有人能向我解释一下下面发生了什么吗?问题:
movl $0x5,-0x4(%rbp)
;%
和negative 0x4
是什么意思?int main(int argc, char* argv[])
{
int i = 5; // line 25
i ++; // line 26
}
-----------------------------------------------------
Disassembly:
25 int i = 5;
00000000004014f4: movl $0x5,-0x4(%rbp)
26 i ++;
00000000004014fb: addl $0x1,-0x4(%rbp)
-----------------------------------------------------
Register Values:
rbp: 0x23fe60
-----------------------------------------------------
Memory map at line 25:
Address | 0-3 | 4-7 | 8-B | C-F |
0x23fe60 |00000000|00000000|00000000|05000000|
Memory map at line 26:
Address | 0-3 | 4-7 | 8-B | C-F |
0x23fe60 |00000000|00000000|00000000|06000000|
注意:上面的内容是由Eclipse生成的,我正在使用64位机器上的mingw进行编译。
发布于 2014-10-04 15:52:06
因为你的编译器不喜欢。它决定将变量i
放在堆栈上。
rbp
不包含内存缓存的地址。rbp
是指向堆栈底部的基本指针。-0x4(%rbp)
是变量i
在内存中的位置(在堆栈上)。意思是rbp减去4,为什么是4?因为i
需要4个字节。这就是i
的地址。
请参阅Stack
movl $0x5,-0x4(%rbp)
__;%
和negative 0x4
是什么意思?有两个公共程序集语法。
不幸的是,您的代码在AT&T中。%
是AT&T语法中引用变量的方式。-0x4
是数字-4
的十六进制表示(见上面的答案)。
请参阅language#Syntax
发布于 2014-10-04 15:48:10
-0x4(%rbp)
意味着在偏移量4(向后返回到那个点)到寄存器rbp中,变量i位于。在这里了解更多关于堆栈工作方式及其框架的内容:http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Mips/stack.htmlmovl $0x5,-0x4(%rbp)
是有效的,而且您是正确的,从Intel语法世界来看,这似乎很奇怪。但实际上,这是AT&T语法代码的一个例子。请阅读此处以获得更多解释:language#Syntax我真的认为你会从阅读这篇文章中获益:http://lwn.net/Articles/250967,当我思考关于记忆的“大图”时,它真的帮了我很多忙。
发布于 2014-10-04 15:48:34
- register rbp contains the base of the stack frame of the function, it's where local automatic variables are allocated from, this is specified by the calling convention of your language.
- in this case the mov instruction is a move of an immediate value to the memory location. The % prefaces a register name. Since stacks grow downwards traditionally the offset of the local automatic variable is a negative offset from the base of the frame/stack.
https://stackoverflow.com/questions/26194365
复制相似问题