Guest User

Untitled

a guest
Jun 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. /*
  2.  
  3. do it like this:
  4.  
  5. gcc hello.c -o hello && ./hello
  6.  
  7. */
  8.  
  9.  
  10. #include <sys/types.h>
  11. #include <string.h>
  12.  
  13. #if defined(__x86_64__)
  14. static inline u_int64_t rdtsc (void)
  15. {
  16. u_int64_t a = 0, d = 0;
  17. __asm__ __volatile__ ("rdtsc\n" : "=a" (a), "=d" (d));
  18. return (a | d << 32);
  19. }
  20. #else
  21. #error bye
  22. #endif
  23.  
  24. static inline void print(char byte) {
  25. char *tmp = &byte;
  26. __asm__ __volatile__ ("movq $1, %%rax\n\t"
  27. "movq $1, %%rdi\n\t"
  28. "movq %0, %%rsi\n\t"
  29. "movq $1, %%rdx\n\t"
  30. "syscall\n\t" :: "m" (tmp));
  31. }
  32.  
  33. static char *hi = "what's good\n";
  34.  
  35. int main(void) {
  36. unsigned int i = 0;
  37. unsigned int l = strlen(hi);
  38. while (i<l+1) {
  39. char chomp = (char)rdtsc();
  40. if (chomp == hi[i]) {
  41. print(chomp);
  42. ++i;
  43. }
  44. }
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment