Skip to content

Instantly share code, notes, and snippets.

@mr1337357
Created October 27, 2015 23:44
Show Gist options
  • Save mr1337357/50dcc6d0a16790a862b2 to your computer and use it in GitHub Desktop.
Save mr1337357/50dcc6d0a16790a862b2 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define go(n) __asm__("jmp *%%rax\n"::"a"(n))
void sw(int n) {
volatile void *dests[4] = {&&l0,&&l1,&&l2,&&l3};
go(dests[n]);
l0:
printf("zero\n");
goto end;
l1:
printf("one\n");
goto end;
l2:
printf("two\n");
goto end;
l3:
printf("three\n");
goto end;
end:
return;
}
int main() {
int i;
for(i=0;i<4;i++) {
sw(i);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment