add -0x4(%r12), %eax
cmp %eax, %r12我在组装中得到了这两条生产线。
我的猜测是从r12中的值中减去4,然后将其添加到eax中。
r12是继续从原始值变为-4,还是保持原始值不变?
例如,如果r12 = 5,eax = 3,则add函数将导致eax = 4;
r12仍然是5还是1?
发布于 2016-09-20 09:28:50
您可以自己在gdb中执行这一步,看看它做了什么。设置gdb以显示上一步更改的寄存器(例如,layout reg,请参阅x86 tag wiki的底部)。
由于%r12需要是加法的源操作数的有效指针,因此应将以下内容放入foo.S
.globl _start
_start:
mov %rsp, %r12 # added this instruction: r12 is now a valid pointer to stack memory, since we copy the stack pointer into it
add -0x4(%r12), %eax
# cmp %eax, %r12 # operand-size mismatch is an error
cmp %eax, %r12d # 32-bit compare
cmp %rax, %r12 # 64-bit compare. upper 32 of RAX is zero from writing EAX in the add instruction
# your program will segfault here because we don't make an exit() system call, and instead keep executing whatever bytes are next in memory.使用gcc -g -nostdlib foo.S将其汇编成静态二进制文件。_start is the default entry point。
运行gdb ./a.out
(gdb) layout reg
(gdb) b _start
(gdb) r
(gdb) si # step instruction,
# repeat as necessary and watch gdb highlight changed registers.我喜欢set disassembly-flavor intel而不是AT&T语法,但是如果你喜欢(或者想/需要学习AT&T语法),那就不要学。
Hint、CMP doesn't modify either of its operands和ADD仅使用R12作为加载4字节源数据的寻址模式。
EAX的最终值取决于内存中的内容。
发布于 2016-09-20 08:42:25
这不会更改r12;它只是使用它来计算地址。
https://stackoverflow.com/questions/39584046
复制相似问题