在运行时将机器代码插入到 C 代码中

Insert machine code into C code at runtime

我目前正在使用 Arduino Uno/Nano 使用 C 语言构建一些东西,我需要在运行时从外部将一些已编译的代码插入到可执行文件中。

我希望能够像动态链接库一样使用它,我可以在程序中进行交换。

下面是一些代码来说明我的意思:

int external_code(int); // the external code needs to be called some way
void set_external_code(char*); // set the external code that gets executed

如果你打算通过串行加载额外的程序代码,你不能这样做。

来自Arduino docs

Note: Flash (PROGMEM) memory can only be populated at program burn time. You can’t change the values in the flash after the program has started running.

AVR 将程序存储在单独的物理内存(Flash)中。您可以从中读取,但不能像 RAM 和 EEPROM 那样在运行时写入。