Skip to content

Instantly share code, notes, and snippets.

@xavery
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xavery/233e2543747abf1b5d10 to your computer and use it in GitHub Desktop.
Save xavery/233e2543747abf1b5d10 to your computer and use it in GitHub Desktop.
static int sadd(int a, int b)
{
asm (
"addl %1, %0\n\t"
"jo 1f\n\t"
"jmp 4f\n\t"
"1: js 2f\n\t"
"jmp 3f\n\t"
"2: movl $0x7fffffff, %0\n\t"
"jmp 4f\n\t"
"3: movl $~0, %0\n\t"
"4:"
: "=r"(a)
: "r"(b), "0"(a)
: "flags"
);
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment