I'm searching for a good assembly generation module for Python. I have found this one: PyAsm
But it's not working well. I want to execute and generate assembly executable file for simple operations like add, sub, divide and multiply. Something like Reflection.Emit library in .NET.
I'm developing under Linux (Ubuntu 12.10 64bit) and Python2.7.
For example, when I try to compile this simple sub code with PyAsm it gives me a "Segmentation fault (core dumped)":
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()
Reflection.Emit
in .NET doesn't generate assembly, it generates ILCode. ILCode is executed in the .net virtual machine. – Elyssafrom 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()
– Bothersome