简体   繁体   English

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

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

In my assembly program I am interested to know what's the minimal value %rsp gets (as it grows down) compared to its initial value so I wrote in main:在我的汇编程序中,我很想知道 %rsp 得到的最小值(随着它的增长)与其初始值相比是多少,所以我在 main 中写道:

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

and in every part in my code before push (or any other command that may affect %rsp) I wrote:在推送之前(或任何其他可能影响 %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...

but when I debug my code rdx and rcx share the same value, why is that?但是当我调试我的代码时,rdx 和 rcx 共享相同的值,这是为什么呢?

Your stack checking code is in fact correct.您的堆栈检查代码实际上是正确的。 Since you provided full code[*] we can see there is a problem starting from line 73:由于您提供了完整的代码[*],我们可以看到从第 73 行开始存在问题:

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

Your stack check is in between the cmp (%rdi), %esi and the jne continue so it will use the flags from cmp %rsp, %rdx instead.您的堆栈检查位于cmp (%rdi), %esijne continue之间,因此它将使用cmp %rsp, %rdx中的标志。 As it happens those are equal at that point so your function will not go to continue but return.碰巧那些在那个时候是相等的,所以你的 function 不会 go continue但返回。 The stack space used will just be 16 bytes.使用的堆栈空间仅为 16 个字节。 Note this stack check block is useless as the stack pointer can not change from the previous one so you can remove lines 74-80.请注意,此堆栈检查块是无用的,因为堆栈指针不能从前一个更改,因此您可以删除第 74-80 行。 This will then produce a stack usage of 0x40 bytes as you expect.然后,这将产生 0x40 字节的堆栈使用量,如您所料。

As to the question of operand order, at&t uses the reverse to intel.至于操作数顺序的问题,at&t 采用了与 intel 相反的方式。 Consider this code:考虑这段代码:

mov $1, %eax
mov $2, %edx
cmp %eax, %edx
jl next

This will not jump.不会跳。


[*] https://onlinegdb.com/5CKsK1GNT with ja changed back to jl [*] https://onlinegdb.com/5CKsK1GNTja改回jl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM