0x8($ rsp)的含义 [英] Meaning of 0x8($rsp)

查看:984
本文介绍了0x8($ rsp)的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次学习Assembly Lang。这是(gdb)反汇编的一部分:

My first time learning Assembly Lang. Here is a part of (gdb) disassembly:

mov    $0x131,%eax
cmp    0x8(%rsp),%eax  //Question here, what is the value of 0x8(%rsp)?




(gdb)i r
rax            0x131    305
rbx            0x7fffffffe578   140737488348536
rcx            0x20     32
rdx            0x7fffffffe478   140737488348280
rsi            0x0      0
rdi            0x1999999999999999       1844674407370955161
rbp            0x0      0x0
rsp            0x7fffffffe470   0x7fffffffe470
r8             0x37ed3bb080     240203313280
r9             0x0      0
r10            0x1e     30
r11            0x0      0
r12            0x400cb0 4197552
r13            0x7fffffffe570   140737488348528
r14            0x0      0
r15            0x0      0
rip            0x400fd9 0x400fd9 <phase_3+129>
eflags         0x212    [ AF IF ]
cs             0x33     51
ss             0x2b     43
ds             0x0      0
es             0x0      0
fs             0x0      0

我很难弄清楚它的比较。以及 0x8(%rsp)的值是什么。

I have trouble figuring out what does it compare. and what is the value of 0x8(%rsp).

(我知道这个问题听起来很愚蠢)

(I know this question sounds like stupid)

预先感谢

=-=========

=-==========

最后我被

(gdb) p /x *(int *)($rsp+0x8)

借助此帖子如何在gdb中打印-0x4(%rbp)?

Zack的答案应该是正确的,但是由于我使用的是64位操作系统,因此无法正常工作。

Zack's answer should be right, but it is not working since I'm using a 64 bit OS.

推荐答案

取消引用。 0x8(%rsp)的意思是获取堆栈上距离堆栈指针%rsp 8个字节的位置,然后取该地址处的值。

将0x131移动到%eax,并且然后将其与该位置的数据进行比较。 cmp根据该比较设置 eflags 寄存器(例如,如果操作数相等,则为零标志,等等。)

查看地址是什么使用GDB,键入

Parentheses generally mean to dereference. 0x8(%rsp) means "get the location on the stack that is 8 bytes away from the stack pointer %rsp, and then take the value at that address."
It moves 0x131 into %eax, and then compares it to the data at that location. cmp sets the eflags register depending on that comparison (like the Zero Flag if the operands were equal, etc.)
To see what is at the address using GDB, type

(gdb) x/1dw 0x8(%esp)

此命令 x检查内存。

1表示检查指定的任何单位。

d表示以十进制表示的输出(与十六进制相对)。我不知道您要与哪种类型的数据进行比较,因此您可以使用 c获取一个字符,或使用 x获取一个十六进制,或使用 s获取一个字符串,等等。

w提供单位,在本例中为4个字节。

因此,此命令在给定地址4x处查找地址0x8(%rsp)并打印十进制格式的内容。

要了解有关使用GDB查看内存变化的更多信息,请参见此文档。

This command 'x' examines memory.
1 means examine 1 of whatever unit is specified.
"d" means output in decimal notation (as opposed to hex). I don't know what type of data you are making a comparison to, so you might use "c" to get a char, or "x" to get a hex, or "s" for a string, or whatever.
"w" provides the unit, in this case a word, which is 4 bytes.
So this command looks at 4 bytes at the given address, 0x8(%rsp), and prints whatever is there in decimal format.
To learn more about using GDB to see how your memory is changing, see this document.

这篇关于0x8($ rsp)的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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