假设我定义了一个新的
编译器为
我试图根据汇编代码填写
struct
:struct s {
int *x;
struct {
short sh[2];
int i;
} w;
struct s *next;
};
另外,我编写了一个函数来初始化它:
void init_s(struct s *ss) {
ss->w.sh[1] = /* Line 1 */;
ss->x = /* Line 2 */;
ss->next = /* Line 3 */;
}
编译器为
init_s
生成了以下汇编代码:init_s: # line 1
movw 8(%rdi), %ax # line 2
movw %ax, 10(%rdi) # line 3
leaq 12(%rdi), %rax # line 4
movq %rax, (%rdi) # line 5
movq %rdi, 16(%rdi) # line 6
retq # line 7
我试图根据汇编代码填写
init_s
的缺失代码行。我已经弄清楚了第1行和第2行(或者至少我认为是这样)。第1行应该是ss->w.sh[0]
,第2行应该是&(ss->w.sh[2])
。但是,我在第3行遇到了问题。我认为根据汇编代码,它应该是&(ss->x)
,但我觉得这是不正确的,并且不确定为什么会这样。任何反馈或建议都将非常感谢,有助于我更多地了解汇编和结构体。
init_s
只是一个占位符示例,但也许你应该展示一下你用于生成汇编代码的实际编译代码? - AKXinit_s
进行逆向工程。 - Nate Eldredge