mov -0x10(%rbp), %r10 没有将 %r10 设置为正确的值?

问题描述

我正在写一个代码生成问题,其中输出是 x86/64 汇编代码文件。我有以下输出序列

mov -0x8(%rbp),%r10     // r10 = 0 at the moment
mov $0xa,%r11           // r11 = 10
cmp %r11,%r10       
setg -0x10(%rbp)         // -0x10(%rbp) = 0
mov -0x10(%rbp),%r10    // %r10 is desired to be 0,but here is the problem

根据调试器,r10 设置为 r10 0x100000000 4294967296

我不明白为什么 %r10 的内容没有设置为预期值 0

有什么我错过的约定吗?

整个生成的 x86/64 程序是

    .text
    .globl  _f1
_f1:
    pushq   %rbp
    movq    %rsp,%rbp
    subq    $16,%rsp
    movq    %rdi,-8(%rbp)
    jmp f1.start
    .text
f1.start:
    movq    -8(%rbp),%r10
    movq    $10,%r11
    cmpq    %r11,%r10
    setg    -16(%rbp)
    movq    -16(%rbp),%r10
    cmpq    $1,%r10
    je  f1.then
    jmp f1.end
    .text
f1.then:
    movq    $1,%rax
    movq    %rbp,%rsp
    popq    %rbp
    retq    
    .text
f1.end:
    movq    $0,%rsp
    popq    %rbp
    retq    
    .text
    .globl  _f2
_f2:
    pushq   %rbp
    movq    %rsp,-8(%rbp)
    jmp f2.start
    .text
f2.start:
    movq    -8(%rbp),%r10
    je  f2.then
    jmp f2.end
    .text
f2.then:
    movq    $1,%rsp
    popq    %rbp
    retq    
    .text
f2.end:
    movq    $0,%rsp
    popq    %rbp
    retq    
    .text
    .globl  _main
_main:
    pushq   %rbp
    movq    %rsp,%rbp
    subq    $40,%rsp
    movq    $0,%rdi
    callq   _f1
    movq    %rax,-24(%rbp)
    movq    $15,%rdi
    callq   _f2
    movq    %rax,-32(%rbp)
    movq    -24(%rbp),%r10
    movq    -32(%rbp),%r11
    addq    %r10,%r11
    movq    %r11,-40(%rbp)
    movq    -40(%rbp),%rsp
    popq    %rbp
    retq    

您可以将其保存到test.s中,然后通过运行以下命令生成可执行文件 clang -Wno-override-module -O1 -Wall -fno-asynchronous-unwind-tables -mstackrealign -o test test.s

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)