我正在为 Python 寻找一个好的程序集生成模块。我找到了这个: PyAsm
但它运作不佳。我想为简单的操作(如加法、减法、除法和乘法)执行和生成汇编可执行文件。.NET 中的 Reflection.Emit 库之类的东西。
我正在Linux(Ubuntu 12.10 64bit)和Python2.7下开发。
例如,当我尝试使用 PyAsm 编译这个简单的子代码时,它给了我一个“分段错误(核心转储)”:
from ctypes import c_int
from pyasm import Program
from pyasm.instructions import push, mov, ret, pop, sub
from pyasm.registers import eax, esp, ebp
def test():
prog = Program(
push(ebp),
mov(ebp, esp),
mov(eax, ebp.addr+8),
sub(eax, 10),
pop(ebp),
ret(),
)
fun = prog.compile(c_int, [c_int])
assert fun(1234) == 1224
if __name__ == '__main__':
test()