Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- do it like this:
- gcc hello.c -o hello && ./hello
- */
- #include <sys/types.h>
- #include <string.h>
- #if defined(__x86_64__)
- static inline u_int64_t rdtsc (void)
- {
- u_int64_t a = 0, d = 0;
- __asm__ __volatile__ ("rdtsc\n" : "=a" (a), "=d" (d));
- return (a | d << 32);
- }
- #else
- #error bye
- #endif
- static inline void print(char byte) {
- char *tmp = &byte;
- __asm__ __volatile__ ("movq $1, %%rax\n\t"
- "movq $1, %%rdi\n\t"
- "movq %0, %%rsi\n\t"
- "movq $1, %%rdx\n\t"
- "syscall\n\t" :: "m" (tmp));
- }
- static char *hi = "what's good\n";
- int main(void) {
- unsigned int i = 0;
- unsigned int l = strlen(hi);
- while (i<l+1) {
- char chomp = (char)rdtsc();
- if (chomp == hi[i]) {
- print(chomp);
- ++i;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment