动态指令

通过程序动态生成指令,然后进行执行

1
2
3
4
5
6
7
8
9
 +------------> +-------+ <--+生成指令,写入buffer
| | |
+ | |
PC | |
| buffer|
| |
| |
| |
+-------+
1
2
3
4
5
6
7
8
9
10
uint32_t *InstBuf;
InstBuf = (uint32_t)malloc(size);

for (int i = 0; i < 16: i++) {
InstBuf[i] = 0x03e00008; /* JR RA */
}

void (*f)(void);
f = (void (*)(void))(InstBuf);
(*f)();