为什么 JL 命令在我的汇编代码中不起作用?

why JL command doesn't work in my Assembly code?

在我的汇编程序中,我很想知道 %rsp 得到的最小值(随着它的增长)与其初始值相比是多少,所以我在 main 中写道:

mov %rsp, %rcx #start
mov %rsp, %rdx #max

在推送之前我的代码的每个部分(或任何其他可能影响 %rsp 的命令)我写道:

cmp %rsp, %rdx
jl next3 # current rsp is less that prev_max then skip the update of value for max
mov %rsp, %rdx
next3: # every time this is copied I change the number like next4, next5 etc...

但是当我调试我的代码时,rdx 和 rcx 共享相同的值,这是为什么?

您的堆栈检查代码实际上是正确的。由于您提供了完整代码[*],我们可以看到从第 73 行开始存在问题:

    cmp (%rdi), %esi
    
    cmp %rsp, %rdx
    jl next4
    mov %rsp, %rdx
    next4:
    
    jne continue

您的堆栈检查在 cmp (%rdi), %esijne continue 之间,因此它将使用 cmp %rsp, %rdx 中的标志。碰巧它们在那一点上是相等的,所以你的函数不会去 continue 但 return。使用的堆栈 space 将只有 16 个字节。请注意,此堆栈检查块无用,因为堆栈指针不能从前一个更改,因此您可以删除第 74-80 行。这将如您所料产生 0x40 字节的堆栈使用。

关于操作数顺序的问题,at&t与intel相反。考虑这段代码:

mov , %eax
mov , %edx
cmp %eax, %edx
jl next

这将不会跳转。


[*] https://onlinegdb.com/5CKsK1GNTja 变回 jl