Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any good assembly generation module for Python?

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()
like image 281
Seishin Avatar asked Mar 02 '13 13:03

Seishin


1 Answers

Not just an awesome name: https://github.com/Maratyszcza/PeachPy

Looks at it's use in: http://www.yeppp.info

like image 116
bitRAKE Avatar answered Nov 07 '22 14:11

bitRAKE