I am writing a codegen problem, in which the output is x86/64 assembly code file. I have the following output seqeunce
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
according to the debugger, r10 is set to r10 0x100000000 4294967296
I cannot figure out why the content of %r10 is not set to the expected value 0
Is there any convention that I missed ?
the whole generated x86/64 program is
.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, %rax
movq %rbp, %rsp
popq %rbp
retq
.text
.globl _f2
_f2:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movq %rdi, -8(%rbp)
jmp f2.start
.text
f2.start:
movq -8(%rbp), %r10
movq $10, %r11
cmpq %r11, %r10
setg -16(%rbp)
movq -16(%rbp), %r10
cmpq $1, %r10
je f2.then
jmp f2.end
.text
f2.then:
movq $1, %rax
movq %rbp, %rsp
popq %rbp
retq
.text
f2.end:
movq $0, %rax
movq %rbp, %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), %rax
movq %rbp, %rsp
popq %rbp
retq
You can save it into test.s
, and by running following command to generate a executable
clang -Wno-override-module -O1 -Wall -fno-asynchronous-unwind-tables -mstackrealign -o test test.s