asm.h 396 B

123456789101112131415161718192021222324
  1. #pragma once
  2. #include <stdint.h>
  3. #ifdef __AVR_ATmega2560__
  4. // return the current PC (on AVRs with 22bit PC)
  5. static inline void GETPC(uint32_t* v)
  6. {
  7. uint8_t a, b, c;
  8. asm
  9. (
  10. "rcall .\n"
  11. "pop %2\n"
  12. "pop %1\n"
  13. "pop %0\n"
  14. : "=r" (a), "=r" (b), "=r" (c)
  15. );
  16. ((uint8_t*)v)[0] = a;
  17. ((uint8_t*)v)[1] = b;
  18. ((uint8_t*)v)[2] = c;
  19. ((uint8_t*)v)[3] = 0;
  20. }
  21. #endif