Python有没有好的汇编生成模块?
我正在寻找一个适合Python的汇编生成模块。
我找到这个:PyAsm
但是它运行得不太好。
我想执行并生成汇编可执行文件,用于一些简单的操作,比如加、减、除和乘。
我希望有点像.NET中的Reflection.Emit库。
我是在Linux(Ubuntu 12.10 64位)和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()