inline asm
1 2 3 4 5 6 7
| asm volatile ( "asm template" : output_operands : input_operands : clobbers );
|
example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include <stdint.h>
__attribute__((noinline)) int mul_add( int a, int b, int c, int *sum, int *acc) { asm volatile ( "imull %[b], %[a]\n\t" "leal (%[a], %[c]), %[s]\n\t" "addl %[a], %[acc]\n\t" : [a] "+r"(a), [s] "=r"(*sum), [acc] "+r"(*acc) : [b] "r"(b), [c] "r"(c) : "cc", "memory" );
return a; }
|
%[b] 是命名参数, 与后面的[a]对应。
"+r" read-write
"=r" write only, 新定义一次,不读旧值
"r" read only,只读