まず、オンラインで簡単に見つけられるはずの x86 オペコードのリストを入手してください。
関数は次のasm()
順序に従います。
asm ( "assembly code"
: output operands /* optional */
: input operands /* optional */
: list of clobbered registers /* optional */
);
次に、C ラベルに「ジャンプ」できないという大きな問題があります。ラベルを「アセンブリ」ラベルにしてジャンプできるようにする必要があります。元:
int main()
{
asm("jmp .end"); // make a call to jmp there
printf("Hello ");
asm(".end:"); //make a "jumpable" label
printf("World\n");
return 0;
}
このプログラムの出力は、「Hello」を飛び越えたように、単純に「World」です。これは同じ例ですが、比較ジャンプがあります。
int main()
{
int x = 5, i = 0;
asm(".start:");
asm("cmp %0, %1;" // compare input 1 to 2
"jge .end;" // if i >= x, jump to .end
: // no output from this code
: "r" (x), "r" (i)); // input's are var x and i
printf("Hello ");
i++;
asm("jmp .start;");
asm(".end:");
printf("World\n");
return 0;
}