说明:参考狄泰软件学院相关课程
示例如下:
#include <stdio.h> int main() { int result = 0; int input = 1; int a = 1; int b = 2; asm volatile ( "movl %1, %0 " : "=r"(result) : "r"(input) ); printf("result = %d ", result); printf("input = %d ", input); asm volatile ( "movl %%eax, %%ecx " "movl %%ebx, %%eax " "movl %%ecx, %%ebx " : "=a"(a), "=b"(b) : "a"(a), "b"(b) ); printf("a = %d ", a); printf("b = %d ", b); return 0; }
结果如下:
result = 1 input = 1 a = 2 b = 1
示例代码:
#include <stdio.h> int main() { char* s = "D.T.Software "; int l = 13; printf("main begin "); asm volatile( "movl $4, %%eax " "movl $1, %%ebx " "movl %0, %%ecx " "movl %1, %%edx " "int $0x80 " : : "r"(s), "r"(l) : "eax", "ebx", "ecx", "edx" ); asm volatile( "movl $1, %eax " "movl $42, %ebx " "int $0x80 " ); printf("main end "); return 0; }
运行结果: