From: Antonio Ospite Date: Tue, 5 Nov 2013 16:57:56 +0000 (+0100) Subject: Add an inline asm implementation of sum() for x86 CPUs X-Git-Url: https://git.ao2.it/experiments/inline-assembly.git/commitdiff_plain/f9852578fbd1aa0dff434dda1fd1d4d17b1645fc?ds=sidebyside Add an inline asm implementation of sum() for x86 CPUs --- diff --git a/inline-asm-sum.c b/inline-asm-sum.c index 4f9c2f0..a578ee7 100644 --- a/inline-asm-sum.c +++ b/inline-asm-sum.c @@ -21,7 +21,16 @@ static int sum(int a, int b) { +#if defined(__i386__) || defined(__x86_64__) + int ret; + __asm__("addl %2, %1\n\t" + : "=a"(ret) /* %0 bound to %eax */ + : "a"(a), "r"(b) /* %1 is 'a' bound to %eax, %2 is 'b' */ + ); + return ret; +#else return a + b; +#endif } int main(void)