clang编译的代码中jne的规则

The rule of jne in code compiled by clang

源代码:

int main(int argc, const char * argv[]) {

do {
    printf("heihei");
}while (1 < 2);

return 0;}

编译:

LBB0_1:                                 ## =>This Inner Loop Header: Depth=1
leaq    L_.str(%rip), %rdi
movb    [=11=], %al
callq   _printf
movl    %eax, -20(%rbp)         ## 4-byte Spill

movb    , %al
testb   , %al
jne LBB0_1
jmp LBB0_3
LBB0_3:

显然,这个 do-while 循环是无限的。 据我所知,testb $1, %al 会将 ZF 设置为 1。由于 jne 只有在 ZF 为 0 时才会跳转(jne: jump option : ~ZF),为什么流程会跳回到 LBB0_1?

顺便说一句,你有没有学习Clang生成的汇编代码和所有其他相关内容的书籍推荐? (具体来自 objective-c 代码)

WW

test指令说明:

TEST -- Logical Compare

Computes the bit-wise logical AND of first operand (source 1 operand) and the second operand (source 2 operand) and sets the SF, ZF, and PF status flags according to the result. The result is then discarded.

在这种情况下 jnejnz 同义。该指令通常用于测试零值,因此您会看到类似以下内容:

testb   %al, %al
jz      somewhere

关于您的其他问题,您正在寻找的是 GAS(Gnu 汇编器)语法,您可以在互联网上找到大量信息,但请查看 Wikibooks link。