Skip to content

Instantly share code, notes, and snippets.

@evanphx
Created July 11, 2013 17:34
Show Gist options
  • Save evanphx/5977490 to your computer and use it in GitHub Desktop.
Save evanphx/5977490 to your computer and use it in GitHub Desktop.
struct cont {
int (*func)(int);
};
int work(int x) {
return x + 2;
}
int direct(int x) {
return work(x);
}
int indirect(struct cont* f, int x) {
return f->func(x);
}
_work:
0000000000000000 pushq %rbp
0000000000000001 movq %rsp, %rbp
0000000000000004 leal 2(%rdi), %eax
0000000000000007 popq %rbp
0000000000000008 ret
0000000000000009 nopl (%rax)
_direct:
0000000000000010 pushq %rbp
0000000000000011 movq %rsp, %rbp
0000000000000014 popq %rbp
0000000000000015 jmpq 0x1a
000000000000001a nopw (%rax,%rax)
_indirect:
0000000000000020 pushq %rbp
0000000000000021 movq %rsp, %rbp
0000000000000024 movq %rdi, %rax
0000000000000027 movl %esi, %edi
0000000000000029 popq %rbp
000000000000002a jmpq *(%rax)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment