3

代码:

extern inline int strncmp(const char * cs, const char * ct, int count)
{
register int __res;
__asm__("cld\n"
"1:\tdecl %3\n\t"
"js 2f\n\t"
"lodsb\n\t"
"scasb\n\t"
"jne 3f\n\t"
"testb %%al, %%al\n\t"
"jne 1b\n"
"2:\txorl %%eax,%%eax\n\t"
"jmp 4f\n"
"3:\tmovl $1,%%eax\n\t"
"j1 4f\n\t"
"negl %%eax\n"
"4:"
:"=a" (__res):"D" (cs), "S" (ct), "c" (count):"si","di","cx");
return __res;
}

我不明白“ js 2f\n\t ”中的f和“ jne 1b\n ”中的b,如何理解?我应该看哪本书?谢谢你。

4

2 回答 2

9

在这种情况下f,意味着向前和b向后。Sojs 2f表示向前跳转到标签 2,如果 sign set

你会想要调查的gcc inline assembly。我似乎在网上找不到任何参考来包含这一点,但我知道你可以在Professional Assembly Language中找到它。

为什么我们不能使用命名标签?引用书中的一段话:

If you have another asm section in your C code, you cannot use the same labels again, or an error message will result due to duplicate use of labels.

So what can we do ?

The solution is to use local labels. Both conditional and unconditional branches allow you to specify a number as a label, along with a directional flag to indicate which way the processor should look for the numerical label. The first occurrence of the label found will be taken.

About modifiers:

Use the f modifier to indicate the label is forward from the jump instruction. To move backward, you must use the b modifier.

于 2012-11-24T07:19:24.563 回答
1

This is documented in the manual for the assembler.

于 2013-03-16T12:31:13.943 回答