执行汇编code与Python [英] Executing assembler code with python

查看:357
本文介绍了执行汇编code与Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要执行一个Python脚本内组装code。这可能吗?

I want to execute assembly code inside a python script. Is that possible?

在C语言编程会是这样

static inline getesp(){
        __asm__("mov %esp, %eax");
}

但如何做到这一点与Python?这可能吗?

But how to do that with Python? Is it possible?

推荐答案

你可以这样做,这将是写一个(C)扩展为Python的一种方式。你可以看看文档中如何做到这一点的全部细节。

One way you could do this would be to write a (C) extension for Python. You can take a look at this documentation for full details of how to do that.

开发基于C-Python扩展将直接使用 ctypes的外部库接口的另一种方法模块。

Another way of developing C-based Python extensions would be to interface directly with an external library using the ctypes module.

在任何情况下,你需要一些C code编译变成一个图书馆或扩展,一种从Python中调用它。显然你想达到什么这可能不是最优的,但实际上它没有那么多工作,揭露了一些功能。

In any case, you'd need some C code compiled into either a library or an extension and a way to call it from Python. Clearly for what you want to achieve this is probably not optimal but actually its not that much work to expose a few functions.

这篇关于执行汇编code与Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆