Skip to content

Instantly share code, notes, and snippets.

@qguv
Created May 22, 2018 20:24
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 qguv/5ed37cf43e0555174b2c54edbfa22a91 to your computer and use it in GitHub Desktop.
Save qguv/5ed37cf43e0555174b2c54edbfa22a91 to your computer and use it in GitHub Desktop.
/* Input a number and watch it get clobbered by another! */
#include <stdio.h>
#include <stdlib.h>
#define answer(__op1) __asm__ ( \
"movl $42, %0\n\t" \
: "=r" (__op1) \
: "0" (__op1) \
);
int main(int argc, char *argv[])
{
if (argc != 2) {
fputs("Usage: asm_test NUMBER\n", stderr);
exit(EXIT_FAILURE);
}
int x = strtol(argv[1], NULL, 10);
answer(x);
printf("%d\n", x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment