Prusa-Firmware/Firmware/asm.h
Yuri D'Elia bff79d290a GETPC: Do not manipulate the 32bit return address
We can do that offline, saving over 30 bytes of instructions.
2021-06-19 13:56:40 +02:00

25 lines
396 B
C

#pragma once
#include <stdint.h>
#ifdef __AVR_ATmega2560__
// return the current PC (on AVRs with 22bit PC)
static inline void GETPC(uint32_t* v)
{
uint8_t a, b, c;
asm
(
"rcall .\n"
"pop %2\n"
"pop %1\n"
"pop %0\n"
: "=r" (a), "=r" (b), "=r" (c)
);
((uint8_t*)v)[0] = a;
((uint8_t*)v)[1] = b;
((uint8_t*)v)[2] = c;
((uint8_t*)v)[3] = 0;
}
#endif