6

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()
Seishin
  • 1,493
  • 1
  • 19
  • 30
  • `Reflection.Emit` in .NET doesn't generate assembly, it generates ILCode. ILCode is executed in the .net virtual machine. – Femaref Mar 02 '13 at 14:01
  • 1
    Rather than asking for recommendations (which is generally not on-topic here), why don't you show the exact problem you have with PyASM - chances are someone can either help you fix it and/or suggest alternatives. – Mat Mar 02 '13 at 14:02
  • @Femaref, I perfectly know what Reflection.Emit in .NET does. I meant something like this but for x86 assembly. – Seishin Mar 02 '13 at 14:06
  • @Mat, when trying to build one of the predefined tests in the bitbucket it gives me a "Segmentation fault (core dumped)". For example this one: `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()` – Seishin Mar 02 '13 at 14:06
  • Please [edit] your question to add all the necessary information. – Mat Mar 02 '13 at 14:09
  • Why why why? [I'm a compiler](http://stackoverflow.com/questions/2684364/why-arent-programs-written-in-assembly-more-often/2685541#2685541) – danodonovan Mar 02 '13 at 14:31
  • @danodonovan, because I have an university related project - simple C compiler. – Seishin Mar 02 '13 at 14:34
  • 1
    When I was at uni we had to write assembly ourselves (without help from others), pretty much so we could learn it was horrid and we should leave it to compilers. – danodonovan Mar 02 '13 at 14:37
  • I have to learn it too during the first year but now I have to write a whole compiler. So that's why I'm searching for such a module which will automatically and easily generate assembly. – Seishin Mar 02 '13 at 14:40

1 Answers1

3

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

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

Marat Dukhan
  • 11,993
  • 4
  • 27
  • 41
bitRAKE
  • 391
  • 2
  • 9