注册机包
py_register_machine2的Python项目详细描述
Python3的注册机包
您可以查看docs以获得有关设计、使用和完整代码文档的大量信息。
安装pyregistermachine2
py_register_machine2是python3包,因此您只需将项目文件夹放在 $PYTHONPATH。您可以使用echo $PYTHONPATH和python3 -c "import sys; print(sys.path)"获得pythonpath。
因此,您可以使用:
cd /usr/local/lib/python3.5/dist-packages/ git clone https://github.com/daknuett/py_register_machine2
或:
python3 -m pip install py_register_machine2
使用pyregistermachine2
使用准备好的机器
在py_register_machine2.machines中是一组提供寄存器机器定义的模块 这些是返回4元组的函数:(processor, rom, ram, flash),可能需要调用processor.setup_done()。
创建自己的机器
如果准备好的机器不符合您的要求,您可能需要创建自己的机器, 为此,您应该学习docs here。
指令开始、机器代码和装配
机器的指令集由继承自py_register_machine2.core.commands.BaseCommand的obhects定义, 在py_register_machine2.commands中有一组现成的命令。
处理器为操作码读取一个字的数据,解码此操作码,并为n个参数读取n个字的数据。 machinecode可以使用list这样的对象:
program = [0x16, 0x01, 0x01] # using the py_register_machine2.commands.basic_commands instructionset # this equals "ldi 0x01 ECR" and will halt the engine.
此机器代码可以使用
rom.program(program) # or flash.program(program)
py_register_machine2.tools.assembler.assembler中有一个基本的汇编程序,它使用kasm2汇编语言生成 machicode(一个list对象)
汇编程序使用已配置的处理器和开放流生成机器代码:
from io import StringIO processor.setup_done() progstr = "ldi 0x01 ECR" asm = Assembler(processor, StringIO(progstr)) program = asm.assemble()
一旦对rom进行了编程(处理器开始在rom中执行代码),您就可以使用:
processor.run()