3

I have used the NASM assembler to compile a simple assembly file (code below). I am going to then attempt to take this .obj file created, and have Cython link it to a .pyd file, so Python can import it. Basically I need a way of telling Cython to include an .obj file for use with other Cython / Python code.

First, here is my assembly code:

myfunc.asm

;http://www.nasm.us/doc/nasmdoc9.html
global  _myfunc 
section .text
_myfunc:
    push    ebp 
    mov     ebp,esp 
    sub     esp,0x40        ; 64 bytes of local stack space 
    mov     ebx,[ebp+8]     ; first parameter to function
    ; some more code 
    leave
    ret

I compile this code by using nasm -f win32 myfunc.asm

This gives me myfunc.obj, which is what I want to include into a Cython compiled .pyd.

I may be completely mislead, and there may be a better method to do this entirely. Is there a simple one liner extern that I can do to declare an external object from Cython?

P.S. The label _myfunc should be the entry point.

Community
  • 1
  • 1
Nick Pandolfi
  • 993
  • 1
  • 8
  • 22

1 Answers1

1

To call the _myfunc entry point from Cython, you need to declare it:

cdef extern:
    void _myfunc()

After that declaration, you may call _myfunc() in your Cython module as if it were a Python function. Of course, you will need to link myfunc.obj into your .pyd as explained in the answer to your other question.

Community
  • 1
  • 1
user4815162342
  • 141,790
  • 18
  • 296
  • 355