diff options
Diffstat (limited to 'lab1ucode.py')
| -rw-r--r-- | lab1ucode.py | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/lab1ucode.py b/lab1ucode.py index 3def9b8..5c4e0b8 100644 --- a/lab1ucode.py +++ b/lab1ucode.py @@ -1,5 +1,7 @@ import sys +from string import Template + TWOWAY = { "ir": "001", "pm": "010", @@ -144,21 +146,44 @@ def compile(lines): return ["{:02x}: {}".format(addr, line) for addr, line in linked], labels """ - todo - l=1? lsr_exit - b lsr_loop - end->upc + todo: """ print("todo") print("\n".join(todo)) -if __name__ == "__main__": - prog, labels = compile([line.strip() for line in sys.stdin]) - print("prog:") - print("\n".join(prog)) +def write(prog, labels): + #with open("template.mia", "r") as f: + # template = Template(f.read()) + + ucode_pad = 0x80 - len(prog) + ucode = "\n".join(prog + [f"{len(prog)+n:02x}: 0000000" for n in range(ucode_pad)]) + + insts = [ + "load", + "store", + "add", + "sub", + "and", + "lsr", + "bra", + "bne", + "halt", + "cmp", + "bge", + "beq", + ] + inst_locations = "\n".join([f"{i:02x}: {labels[inst]:02x}" for i, inst in enumerate(insts)]) + + print("MyM:") + print(ucode) print() - print("labels:") - for label, label_nr in labels.items(): - print(label, hex(label_nr)) + + print("K1:") + print(inst_locations) + #print(template.safe_substitute(pm)) + + +if __name__ == "__main__": + write(*compile([line.strip() for line in sys.stdin])) |
