Skip to content

Instantly share code, notes, and snippets.

@kohnakagawa
Created July 25, 2019 06:39
Show Gist options
  • Save kohnakagawa/7d8914bc34fe02090c6fd091685463b7 to your computer and use it in GitHub Desktop.
Save kohnakagawa/7d8914bc34fe02090c6fd091685463b7 to your computer and use it in GitHub Desktop.
RISC-Vでprogram counte を取得するためのコード
#include <stdio.h>
#define GET_PC ({ register long tmp asm("a0");\
__asm__ __volatile__ ("auipc %0, 0\n\t": "=r"(tmp));\
tmp; })
int main() {
const int pc = GET_PC;
printf("%x\n", pc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment