Linux下C内联汇编小例子

/*
 ============================================================================
 Name        : GCC.c
 Author      : Gentoo
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int x = 2;
	int y = 3;
	int result = 0;

	asm(
				"xor %%eax, %%eax\n\t"
				"movl %1, %%eax\n\t"
				"add %2, %%eax\n\t"
				"mov %%eax, %0"
				:"=r"(result)   /*output*/
				:"r"(x), "r"(y) /*input*/
				:"%eax"
		);
	printf("%d + %d = %d\n", x, y, result);
	return EXIT_SUCCESS;
}

你可能感兴趣的:(Linux下C内联汇编小例子)