Advertisement
Guest User

Untitled

a guest
Jul 7th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. unsigned char code[] = {
  5.     0x55,               // push   %rbp
  6.     0x48, 0x89, 0xe5,   // mov    %rsp,%rbp
  7.     0x89, 0x7d, 0xfc,   // mov    %edi,-0x4(%rbp)
  8.     0x89, 0x75, 0xf8,   // mov    %esi,-0x8(%rbp)
  9.     0x8b, 0x55, 0xfc,   // mov    -0x4(%rbp),%edx
  10.     0x8b, 0x45, 0xf8,   // mov    -0x8(%rbp),%eax
  11.     0x01, 0xd0,         // add    %edx,%eax
  12.     0x5d,               // pop    %rbp
  13.     0xc3                // ret
  14. };
  15.  
  16.  
  17. int main(void)
  18. {
  19.     int (*f) (int, int) = (int (*) (int, int)) &code;
  20.     int x = 2;
  21.     int y = 2;
  22.     int z = f(x, y);
  23.     printf("%d + %d = %d\n", x, y, z);
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement