且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JIT 代码生成技术

更新时间:2023-11-10 17:44:34

您只需制作程序计数器 指向要执行的代码.请记住,数据可以是数据或代码.在 x86 上,程序计数器是 EIP 寄存器.EIP的IP部分代表指令指针.调用 JMP 指令跳转到一个地址.跳转后EIP会包含这个地址.

You can just make the program counter point to the code you want to execute. Remember that data can be data or code. On x86 the program counter is the EIP register. The IP part of EIP stands for instruction pointer. The JMP instruction is called to jump to an address. After the jump EIP will contain this address.

是否像将助记符指令映射到二进制代码、将其填充到 char* 指针中并将其转换为函数并执行一样笨拙?

Is it something as hacky as mapping the mnemonic instructions to binary codes, stuffing it into an char* pointer and casting it as a function and executing?

是的.这是一种方法.生成的代码将被转换为 C 中的函数指针.

Yes. This is one way of doing it. The resulting code would be cast to a pointer to function in C.