generate machine.py file

This commit is contained in:
2024-03-28 12:23:16 +01:00
parent fa70beb1a4
commit af82eb5b00
3 changed files with 23 additions and 13 deletions

View File

@@ -100,15 +100,22 @@ class Ram(object):
### example
input_registers = [10, 5, 1]
# input_registers = [10, 5, 1]
#
# instructions = [
# {'op': Ram.op, 'args': ('ADD', ('i', 0), ('value', 1), ('o', 2))},
# {'op': Ram.op, 'args': ('ADD', ('value', 0), ('@', 2, 'i', 'i'), ('o', 1))},
# ]
instructions = [
{'op': Ram.op, 'args': ('ADD', ('i', 0), ('value', 1), ('o', 2))},
{'op': Ram.op, 'args': ('ADD', ('value', 0), ('@', 2, 'i', 'i'), ('o', 1))},
]
# input_registers = [10, 5, 1, 2, 4]
# instructions = [ {"op": Ram.op, "args": ('ADD', ('i', 0), ('value', 1), ('r', 0))},
# {"op": Ram.op, "args": ('SUB', ('i', 1), ('value', 3), ('r', 1))},
# {"op": Ram.op, "args": ('MULT', ('r', 1), ('r', 0), ('o', 1))},
# ]
ram = Ram(instructions, input_registers)
ram.execute()
# ram = Ram(instructions, input_registers)
print("Result:", ram.output_registers)
# ram.execute()
# print("Result:", ram.output_registers)