在Python中编写一个简短命令,编译并执行32位汇编代码

时间:2016-02-04 16:46:15

标签: python linux assembly

目前我使用NASM作为我的主编译器,Geany作为我正在编写代码的程序。我正在使用linux mint,这就是为什么我不使用MASM。

我想导入操作系统并尝试从那里运行命令。这是我的代码到目前为止的样子:

# This program compiles and runs ASM code in the terminal

import os

if __name__ == "__main__":
    program_name = raw_input("Enter program name: ")
    one = "cd"
    two = "cd /home/daniel/Desktop/CS3b"
    three = "nasm -f elf "+program_name+".asm"
    four = "ld -m elf_i386 -s -o "+program_name+" "+program_name+".o"
    five = "./"+program_name
    os.system(one)
    os.system(two)
    os.system(three)
    os.system(four)
    os.system(five)

当我将代码手动输入终端时,它会完美地编译和执行。但是,当我在终端中运行此命令时,我收到此错误消息。

/home/daniel/Desktop/CS3b/compiler.py: 2: /home/daniel/Desktop/CS3b/compiler.py:: not found

当我尝试将计算程序作为.pyc文件运行时,没有任何反应(或似乎没有任何反应)。

0 个答案:

没有答案
相关问题