Created
March 26, 2024 15:49
-
-
Save betelgeuse-7/adca0e831e3d49e8b843b6870eaec4ff to your computer and use it in GitHub Desktop.
A simple example of extended inline assembly syntax of GCC that outputs the integer representations of some of the 64-bit x86 general-purpose registers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
long rax, rbx, rcx, rdx, rdi, rsi, rsp, rbp; | |
asm ( | |
"movq %%rax, %0\n" | |
"movq %%rbx, %1\n" | |
"movq %%rcx, %2\n" | |
"movq %%rdx, %3\n" | |
"movq %%rdi, %4\n" | |
"movq %%rsi, %5\n" | |
"movq %%rsp, %6\n" | |
"movq %%rbp, %7\n" | |
: "=r" (rax), | |
"=r" (rbx), | |
"=r" (rcx), | |
"=r" (rdx), | |
"=r" (rdi), | |
"=r" (rsi), | |
"=r" (rsp), | |
"=r" (rbp) | |
); | |
printf("rax=%ld\n" | |
"rbx=%ld\n" | |
"rcx=%ld\n" | |
"rdx=%ld\n" | |
"rdi=%ld\n" | |
"rsi=%ld\n" | |
"rsp=%ld\n" | |
"rbp=%ld\n", | |
rax, rbx, rcx, rdx, rdi, rsi, rsp, rbp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment