46 lines · cpp
1#include <cinttypes>2#include <cstdint>3#include <cstdio>4 5int main() {6 constexpr uint64_t fill = 0x0F0F0F0F0F0F0F0F;7 8 uint64_t rax, rbx, rcx, rdx, rsp, rbp, rsi, rdi;9 10 asm volatile(11 // save rsp & rbp12 "movq %%rsp, %4\n\t"13 "movq %%rbp, %5\n\t"14 "\n\t"15 "movq %8, %%rax\n\t"16 "movq %8, %%rbx\n\t"17 "movq %8, %%rcx\n\t"18 "movq %8, %%rdx\n\t"19 "movq %8, %%rsp\n\t"20 "movq %8, %%rbp\n\t"21 "movq %8, %%rsi\n\t"22 "movq %8, %%rdi\n\t"23 "\n\t"24 "int3\n\t"25 "\n\t"26 // swap saved & current rsp & rbp27 "xchgq %%rsp, %4\n\t"28 "xchgq %%rbp, %5\n\t"29 : "=a"(rax), "=b"(rbx), "=c"(rcx), "=d"(rdx), "=r"(rsp), "=r"(rbp),30 "=S"(rsi), "=D"(rdi)31 : "g"(fill)32 :33 );34 35 printf("rax = 0x%016" PRIx64 "\n", rax);36 printf("rbx = 0x%016" PRIx64 "\n", rbx);37 printf("rcx = 0x%016" PRIx64 "\n", rcx);38 printf("rdx = 0x%016" PRIx64 "\n", rdx);39 printf("rsp = 0x%016" PRIx64 "\n", rsp);40 printf("rbp = 0x%016" PRIx64 "\n", rbp);41 printf("rsi = 0x%016" PRIx64 "\n", rsi);42 printf("rdi = 0x%016" PRIx64 "\n", rdi);43 44 return 0;45}46