私はこれに似た実世界のプログラムを持っています、それを私は呼びますtest.cpp
:
#include <stdlib.h>
extern void f(size_t i);
int sample(size_t x)
{
size_t a = x;
size_t i;
for (i = a-2; i>=0; i--) {
f(i);
}
}
そして私の問題は、私が無限ループであるということです。
次のコマンドを実行した場合:
g++ -S -o test.s test.cpp
次のアセンブリシーケンスを取得します。
.file "test.cpp"
.text
.globl _Z6samplem
.type _Z6samplem, @function
_Z6samplem:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $32, %rsp
movq %rdi, -24(%rbp)
movq -24(%rbp), %rax
movq %rax, -8(%rbp)
movq -8(%rbp), %rax
subq $2, %rax
movq %rax, -16(%rbp)
.L2:
movq -16(%rbp), %rax
movq %rax, %rdi
call _Z1fm
subq $1, -16(%rbp)
jmp .L2
.cfi_endproc
.LFE0:
.size _Z6samplem, .-_Z6samplem
.ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
.section .note.GNU-stack,"",@progbits
私はアセンブリ言語の専門家ではありませんが、比較のためのコードとi >= 0
、ループからの条件付きジャンプが表示されることを期待しています。何が起きてる??
UbuntuLinux上のGNUC++4.6.3