summaryrefslogtreecommitdiffstats
path: root/lab1ucode.py
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2022-01-26 23:04:20 +0100
committerGustav Sörnäs <gustav@sornas.net>2022-01-26 23:04:20 +0100
commit049f91d8c7224062a8ad3ca316bc8454c9d15944 (patch)
tree2035fc10e07aa488f86ca2945b27bdace82fcdaf /lab1ucode.py
parent35f34d203f2720503bea92e1bcbca49bea4b16a9 (diff)
downloadtsea83-049f91d8c7224062a8ad3ca316bc8454c9d15944.tar.gz
gen k1
Diffstat (limited to 'lab1ucode.py')
-rw-r--r--lab1ucode.py47
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]))