diff options
Diffstat (limited to 'lab1')
| -rw-r--r-- | lab1/.gitignore | 1 | ||||
| -rw-r--r-- | lab1/Makefile | 23 | ||||
| -rw-r--r-- | lab1/lab1-postamble.mia | 52 | ||||
| -rw-r--r-- | lab1/lab1-test.in | 25 | ||||
| -rw-r--r-- | lab1/lab1-test.mia | 458 | ||||
| -rw-r--r-- | lab1/lab1-upg2.in | 30 | ||||
| -rw-r--r-- | lab1/lab1-upg2.mia | 458 | ||||
| -rw-r--r-- | lab1/lab1-upg3.in | 62 | ||||
| -rw-r--r-- | lab1/lab1-upg3.mia | 458 | ||||
| -rw-r--r-- | lab1/lab1asm.py | 79 | ||||
| -rw-r--r-- | lab1/lab1ucode.in | 95 | ||||
| -rw-r--r-- | lab1/lab1ucode.py | 198 | ||||
| -rw-r--r-- | lab1/todo | 8 |
13 files changed, 1947 insertions, 0 deletions
diff --git a/lab1/.gitignore b/lab1/.gitignore new file mode 100644 index 0000000..f47cb20 --- /dev/null +++ b/lab1/.gitignore @@ -0,0 +1 @@ +*.out diff --git a/lab1/Makefile b/lab1/Makefile new file mode 100644 index 0000000..7ad317d --- /dev/null +++ b/lab1/Makefile @@ -0,0 +1,23 @@ +PYTHON := python3.10 + +.PHONY: all clean +all: lab1-upg2.mia lab1-upg3.mia lab1-test.mia + +clean: + rm -f *.out + +lab1-%.out: lab1-%.in lab1asm.py + $(info compiling $@) + @${PYTHON} lab1asm.py < $< > $@ + +lab1ucode.out: lab1ucode.in lab1ucode.py + $(info compiling ucode) + @${PYTHON} lab1ucode.py < $< > $@ + +lab1-%.mia: lab1-%.out lab1ucode.out lab1-postamble.mia + $(info linking $@) + @cat $< > $@ + @echo "" >> $@ + @cat lab1ucode.out >> $@ + @echo "" >> $@ + @cat lab1-postamble.mia >> $@ diff --git a/lab1/lab1-postamble.mia b/lab1/lab1-postamble.mia new file mode 100644 index 0000000..d2be440 --- /dev/null +++ b/lab1/lab1-postamble.mia @@ -0,0 +1,52 @@ +K2: +00: 04 +01: 06 +02: 09 +03: 0c + +PC: +00 + +ASR: +00 + +AR: +0000 + +HR: +0000 + +GR0: +0000 + +GR1: +0000 + +GR2: +0000 + +GR3: +0000 + +IR: +0000 + +MyPC: +00 + +SMyPC: +00 + +LC: +00 + +O_flag: + +C_flag: + +N_flag: + +Z_flag: + +L_flag: +End_of_dump_file diff --git a/lab1/lab1-test.in b/lab1/lab1-test.in new file mode 100644 index 0000000..82ad549 --- /dev/null +++ b/lab1/lab1-test.in @@ -0,0 +1,25 @@ +bra yes + +no: +load 0 1 +00ee +store 0 0 1a +halt + +yes2: +load 0 1 +00ff +store 0 0 1b +halt + +yes: +load 0 1 +00ff +store 0 0 1a +bra yes2 + +no2: +load 0 1 +00ee +store 0 0 1b +halt diff --git a/lab1/lab1-test.mia b/lab1/lab1-test.mia new file mode 100644 index 0000000..987e4c4 --- /dev/null +++ b/lab1/lab1-test.mia @@ -0,0 +1,458 @@ +PM: +00: 6008 +01: 0100 +02: 00ee +03: 101a +04: 8000 +05: 0100 +06: 00ff +07: 101b +08: 8000 +09: 0100 +0a: 00ff +0b: 101a +0c: 60f8 +0d: 0100 +0e: 00ee +0f: 101b +10: 8000 +11: 0000 +12: 0000 +13: 0000 +14: 0000 +15: 0000 +16: 0000 +17: 0000 +18: 0000 +19: 0000 +1a: 0000 +1b: 0000 +1c: 0000 +1d: 0000 +1e: 0000 +1f: 0000 +20: 0000 +21: 0000 +22: 0000 +23: 0000 +24: 0000 +25: 0000 +26: 0000 +27: 0000 +28: 0000 +29: 0000 +2a: 0000 +2b: 0000 +2c: 0000 +2d: 0000 +2e: 0000 +2f: 0000 +30: 0000 +31: 0000 +32: 0000 +33: 0000 +34: 0000 +35: 0000 +36: 0000 +37: 0000 +38: 0000 +39: 0000 +3a: 0000 +3b: 0000 +3c: 0000 +3d: 0000 +3e: 0000 +3f: 0000 +40: 0000 +41: 0000 +42: 0000 +43: 0000 +44: 0000 +45: 0000 +46: 0000 +47: 0000 +48: 0000 +49: 0000 +4a: 0000 +4b: 0000 +4c: 0000 +4d: 0000 +4e: 0000 +4f: 0000 +50: 0000 +51: 0000 +52: 0000 +53: 0000 +54: 0000 +55: 0000 +56: 0000 +57: 0000 +58: 0000 +59: 0000 +5a: 0000 +5b: 0000 +5c: 0000 +5d: 0000 +5e: 0000 +5f: 0000 +60: 0000 +61: 0000 +62: 0000 +63: 0000 +64: 0000 +65: 0000 +66: 0000 +67: 0000 +68: 0000 +69: 0000 +6a: 0000 +6b: 0000 +6c: 0000 +6d: 0000 +6e: 0000 +6f: 0000 +70: 0000 +71: 0000 +72: 0000 +73: 0000 +74: 0000 +75: 0000 +76: 0000 +77: 0000 +78: 0000 +79: 0000 +7a: 0000 +7b: 0000 +7c: 0000 +7d: 0000 +7e: 0000 +7f: 0000 +80: 0000 +81: 0000 +82: 0000 +83: 0000 +84: 0000 +85: 0000 +86: 0000 +87: 0000 +88: 0000 +89: 0000 +8a: 0000 +8b: 0000 +8c: 0000 +8d: 0000 +8e: 0000 +8f: 0000 +90: 0000 +91: 0000 +92: 0000 +93: 0000 +94: 0000 +95: 0000 +96: 0000 +97: 0000 +98: 0000 +99: 0000 +9a: 0000 +9b: 0000 +9c: 0000 +9d: 0000 +9e: 0000 +9f: 0000 +a0: 0000 +a1: 0000 +a2: 0000 +a3: 0000 +a4: 0000 +a5: 0000 +a6: 0000 +a7: 0000 +a8: 0000 +a9: 0000 +aa: 0000 +ab: 0000 +ac: 0000 +ad: 0000 +ae: 0000 +af: 0000 +b0: 0000 +b1: 0000 +b2: 0000 +b3: 0000 +b4: 0000 +b5: 0000 +b6: 0000 +b7: 0000 +b8: 0000 +b9: 0000 +ba: 0000 +bb: 0000 +bc: 0000 +bd: 0000 +be: 0000 +bf: 0000 +c0: 0000 +c1: 0000 +c2: 0000 +c3: 0000 +c4: 0000 +c5: 0000 +c6: 0000 +c7: 0000 +c8: 0000 +c9: 0000 +ca: 0000 +cb: 0000 +cc: 0000 +cd: 0000 +ce: 0000 +cf: 0000 +d0: 0000 +d1: 0000 +d2: 0000 +d3: 0000 +d4: 0000 +d5: 0000 +d6: 0000 +d7: 0000 +d8: 0000 +d9: 0000 +da: 0000 +db: 0000 +dc: 0000 +dd: 0000 +de: 0000 +df: 0000 +e0: 0000 +e1: 0000 +e2: 0000 +e3: 0000 +e4: 0000 +e5: 0000 +e6: 0000 +e7: 0000 +e8: 0000 +e9: 0000 +ea: 0000 +eb: 0000 +ec: 0000 +ed: 0000 +ee: 0000 +ef: 0000 +f0: 0000 +f1: 0000 +f2: 0000 +f3: 0000 +f4: 0000 +f5: 0000 +f6: 0000 +f7: 0000 +f8: 0000 +f9: 0000 +fa: 0000 +fb: 0000 +fc: 0000 +fd: 0000 +fe: 0000 +ff: 0000 + +MyM: +00: 00f8000 +01: 0088000 +02: 0002000 +03: 0000100 +04: 0078000 +05: 0000080 +06: 00f8000 +07: 0002000 +08: 0000080 +09: 0078000 +0a: 00b8000 +0b: 0000080 +0c: 0240000 +0d: 1184000 +0e: 0138000 +0f: 0000080 +10: 00b0000 +11: 0000180 +12: 0190000 +13: 0000180 +14: 0280000 +15: 0980000 +16: 0130000 +17: 0000180 +18: 0380000 +19: 0a80000 +1a: 0130000 +1b: 0000180 +1c: 0380000 +1d: 0c80000 +1e: 0130000 +1f: 0000180 +20: 0380000 +21: 0081000 +22: 0000626 +23: 0000800 +24: 1a00000 +25: 0000322 +26: 0130000 +27: 0000180 +28: 02c0000 +29: 1040000 +2a: 0118000 +2b: 0000180 +2c: 02c0000 +2d: 000042f +2e: 1040000 +2f: 0118000 +30: 0000180 +31: 0000780 +32: 0380000 +33: 0a80000 +34: 0000180 +35: 02c0000 +36: 00004b9 +37: 00005bc +38: 000033b +39: 00005bb +3a: 000033c +3b: 1040000 +3c: 0118000 +3d: 0000180 +3e: 02c0000 +3f: 0000441 +40: 0000342 +41: 1040000 +42: 0118000 +43: 0000180 +44: 0000344 +45: 0000000 +46: 0000000 +47: 0000000 +48: 0000000 +49: 0000000 +4a: 0000000 +4b: 0000000 +4c: 0000000 +4d: 0000000 +4e: 0000000 +4f: 0000000 +50: 0000000 +51: 0000000 +52: 0000000 +53: 0000000 +54: 0000000 +55: 0000000 +56: 0000000 +57: 0000000 +58: 0000000 +59: 0000000 +5a: 0000000 +5b: 0000000 +5c: 0000000 +5d: 0000000 +5e: 0000000 +5f: 0000000 +60: 0000000 +61: 0000000 +62: 0000000 +63: 0000000 +64: 0000000 +65: 0000000 +66: 0000000 +67: 0000000 +68: 0000000 +69: 0000000 +6a: 0000000 +6b: 0000000 +6c: 0000000 +6d: 0000000 +6e: 0000000 +6f: 0000000 +70: 0000000 +71: 0000000 +72: 0000000 +73: 0000000 +74: 0000000 +75: 0000000 +76: 0000000 +77: 0000000 +78: 0000000 +79: 0000000 +7a: 0000000 +7b: 0000000 +7c: 0000000 +7d: 0000000 +7e: 0000000 +7f: 0000000 + +K1: +00: 10 +01: 12 +02: 14 +03: 18 +04: 1c +05: 20 +06: 28 +07: 2c +08: 31 +09: 32 +0a: 35 +0b: 3e +0c: 00 +0d: 00 +0e: 00 +0f: 00 + +K2: +00: 04 +01: 06 +02: 09 +03: 0c + +PC: +00 + +ASR: +00 + +AR: +0000 + +HR: +0000 + +GR0: +0000 + +GR1: +0000 + +GR2: +0000 + +GR3: +0000 + +IR: +0000 + +MyPC: +00 + +SMyPC: +00 + +LC: +00 + +O_flag: + +C_flag: + +N_flag: + +Z_flag: + +L_flag: +End_of_dump_file diff --git a/lab1/lab1-upg2.in b/lab1/lab1-upg2.in new file mode 100644 index 0000000..10d9586 --- /dev/null +++ b/lab1/lab1-upg2.in @@ -0,0 +1,30 @@ +load 0 0 fe +and 0 1 +000f +store 0 0 ff + +load 0 0 fe +lsr 0 1 +0004 +and 0 1 +000f +add 0 0 ff +store 0 0 ff + +load 0 0 fe +lsr 0 1 +0008 +and 0 1 +000f +add 0 0 ff +store 0 0 ff + +load 0 0 fe +lsr 0 1 +000c +and 0 1 +000f +add 0 0 ff +store 0 0 ff + +halt diff --git a/lab1/lab1-upg2.mia b/lab1/lab1-upg2.mia new file mode 100644 index 0000000..8f2b0cb --- /dev/null +++ b/lab1/lab1-upg2.mia @@ -0,0 +1,458 @@ +PM: +00: 00fe +01: 4100 +02: 000f +03: 10ff +04: 00fe +05: 5100 +06: 0004 +07: 4100 +08: 000f +09: 20ff +0a: 10ff +0b: 00fe +0c: 5100 +0d: 0008 +0e: 4100 +0f: 000f +10: 20ff +11: 10ff +12: 00fe +13: 5100 +14: 000c +15: 4100 +16: 000f +17: 20ff +18: 10ff +19: 8000 +1a: 0000 +1b: 0000 +1c: 0000 +1d: 0000 +1e: 0000 +1f: 0000 +20: 0000 +21: 0000 +22: 0000 +23: 0000 +24: 0000 +25: 0000 +26: 0000 +27: 0000 +28: 0000 +29: 0000 +2a: 0000 +2b: 0000 +2c: 0000 +2d: 0000 +2e: 0000 +2f: 0000 +30: 0000 +31: 0000 +32: 0000 +33: 0000 +34: 0000 +35: 0000 +36: 0000 +37: 0000 +38: 0000 +39: 0000 +3a: 0000 +3b: 0000 +3c: 0000 +3d: 0000 +3e: 0000 +3f: 0000 +40: 0000 +41: 0000 +42: 0000 +43: 0000 +44: 0000 +45: 0000 +46: 0000 +47: 0000 +48: 0000 +49: 0000 +4a: 0000 +4b: 0000 +4c: 0000 +4d: 0000 +4e: 0000 +4f: 0000 +50: 0000 +51: 0000 +52: 0000 +53: 0000 +54: 0000 +55: 0000 +56: 0000 +57: 0000 +58: 0000 +59: 0000 +5a: 0000 +5b: 0000 +5c: 0000 +5d: 0000 +5e: 0000 +5f: 0000 +60: 0000 +61: 0000 +62: 0000 +63: 0000 +64: 0000 +65: 0000 +66: 0000 +67: 0000 +68: 0000 +69: 0000 +6a: 0000 +6b: 0000 +6c: 0000 +6d: 0000 +6e: 0000 +6f: 0000 +70: 0000 +71: 0000 +72: 0000 +73: 0000 +74: 0000 +75: 0000 +76: 0000 +77: 0000 +78: 0000 +79: 0000 +7a: 0000 +7b: 0000 +7c: 0000 +7d: 0000 +7e: 0000 +7f: 0000 +80: 0000 +81: 0000 +82: 0000 +83: 0000 +84: 0000 +85: 0000 +86: 0000 +87: 0000 +88: 0000 +89: 0000 +8a: 0000 +8b: 0000 +8c: 0000 +8d: 0000 +8e: 0000 +8f: 0000 +90: 0000 +91: 0000 +92: 0000 +93: 0000 +94: 0000 +95: 0000 +96: 0000 +97: 0000 +98: 0000 +99: 0000 +9a: 0000 +9b: 0000 +9c: 0000 +9d: 0000 +9e: 0000 +9f: 0000 +a0: 0000 +a1: 0000 +a2: 0000 +a3: 0000 +a4: 0000 +a5: 0000 +a6: 0000 +a7: 0000 +a8: 0000 +a9: 0000 +aa: 0000 +ab: 0000 +ac: 0000 +ad: 0000 +ae: 0000 +af: 0000 +b0: 0000 +b1: 0000 +b2: 0000 +b3: 0000 +b4: 0000 +b5: 0000 +b6: 0000 +b7: 0000 +b8: 0000 +b9: 0000 +ba: 0000 +bb: 0000 +bc: 0000 +bd: 0000 +be: 0000 +bf: 0000 +c0: 0000 +c1: 0000 +c2: 0000 +c3: 0000 +c4: 0000 +c5: 0000 +c6: 0000 +c7: 0000 +c8: 0000 +c9: 0000 +ca: 0000 +cb: 0000 +cc: 0000 +cd: 0000 +ce: 0000 +cf: 0000 +d0: 0000 +d1: 0000 +d2: 0000 +d3: 0000 +d4: 0000 +d5: 0000 +d6: 0000 +d7: 0000 +d8: 0000 +d9: 0000 +da: 0000 +db: 0000 +dc: 0000 +dd: 0000 +de: 0000 +df: 0000 +e0: 0000 +e1: 0000 +e2: 0000 +e3: 0000 +e4: 0000 +e5: 0000 +e6: 0000 +e7: 0000 +e8: 0000 +e9: 0000 +ea: 0000 +eb: 0000 +ec: 0000 +ed: 0000 +ee: 0000 +ef: 0000 +f0: 0000 +f1: 0000 +f2: 0000 +f3: 0000 +f4: 0000 +f5: 0000 +f6: 0000 +f7: 0000 +f8: 0000 +f9: 0000 +fa: 0000 +fb: 0000 +fc: 0000 +fd: 0000 +fe: 0000 +ff: 0000 + +MyM: +00: 00f8000 +01: 0088000 +02: 0002000 +03: 0000100 +04: 0078000 +05: 0000080 +06: 00f8000 +07: 0002000 +08: 0000080 +09: 0078000 +0a: 00b8000 +0b: 0000080 +0c: 0240000 +0d: 1184000 +0e: 0138000 +0f: 0000080 +10: 00b0000 +11: 0000180 +12: 0190000 +13: 0000180 +14: 0280000 +15: 0980000 +16: 0130000 +17: 0000180 +18: 0380000 +19: 0a80000 +1a: 0130000 +1b: 0000180 +1c: 0380000 +1d: 0c80000 +1e: 0130000 +1f: 0000180 +20: 0380000 +21: 0081000 +22: 0000626 +23: 0000800 +24: 1a00000 +25: 0000322 +26: 0130000 +27: 0000180 +28: 02c0000 +29: 1040000 +2a: 0118000 +2b: 0000180 +2c: 02c0000 +2d: 000042f +2e: 1040000 +2f: 0118000 +30: 0000180 +31: 0000780 +32: 0380000 +33: 0a80000 +34: 0000180 +35: 02c0000 +36: 00004b9 +37: 00005bc +38: 000033b +39: 00005bb +3a: 000033c +3b: 1040000 +3c: 0118000 +3d: 0000180 +3e: 02c0000 +3f: 0000441 +40: 0000342 +41: 1040000 +42: 0118000 +43: 0000180 +44: 0000344 +45: 0000000 +46: 0000000 +47: 0000000 +48: 0000000 +49: 0000000 +4a: 0000000 +4b: 0000000 +4c: 0000000 +4d: 0000000 +4e: 0000000 +4f: 0000000 +50: 0000000 +51: 0000000 +52: 0000000 +53: 0000000 +54: 0000000 +55: 0000000 +56: 0000000 +57: 0000000 +58: 0000000 +59: 0000000 +5a: 0000000 +5b: 0000000 +5c: 0000000 +5d: 0000000 +5e: 0000000 +5f: 0000000 +60: 0000000 +61: 0000000 +62: 0000000 +63: 0000000 +64: 0000000 +65: 0000000 +66: 0000000 +67: 0000000 +68: 0000000 +69: 0000000 +6a: 0000000 +6b: 0000000 +6c: 0000000 +6d: 0000000 +6e: 0000000 +6f: 0000000 +70: 0000000 +71: 0000000 +72: 0000000 +73: 0000000 +74: 0000000 +75: 0000000 +76: 0000000 +77: 0000000 +78: 0000000 +79: 0000000 +7a: 0000000 +7b: 0000000 +7c: 0000000 +7d: 0000000 +7e: 0000000 +7f: 0000000 + +K1: +00: 10 +01: 12 +02: 14 +03: 18 +04: 1c +05: 20 +06: 28 +07: 2c +08: 31 +09: 32 +0a: 35 +0b: 3e +0c: 00 +0d: 00 +0e: 00 +0f: 00 + +K2: +00: 04 +01: 06 +02: 09 +03: 0c + +PC: +00 + +ASR: +00 + +AR: +0000 + +HR: +0000 + +GR0: +0000 + +GR1: +0000 + +GR2: +0000 + +GR3: +0000 + +IR: +0000 + +MyPC: +00 + +SMyPC: +00 + +LC: +00 + +O_flag: + +C_flag: + +N_flag: + +Z_flag: + +L_flag: +End_of_dump_file diff --git a/lab1/lab1-upg3.in b/lab1/lab1-upg3.in new file mode 100644 index 0000000..1f0a437 --- /dev/null +++ b/lab1/lab1-upg3.in @@ -0,0 +1,62 @@ +label1: +; lista_sorterad = 1 +load 0 1 +0001 +store 0 0 d0 + +; addr = e0 +load 0 1 +00e0 +store 0 0 d1 + +label2: +; tmp1 = pm(addr) +load 0 2 d1 +store 0 0 d3 + +; tmp2 = pm(addr + 1) +load 0 0 d1 +add 0 1 +0001 +store 0 0 d2 +load 0 2 d2 +store 0 0 d4 + +; tmp1 > tmp2? +load 0 0 d3 +cmp 0 0 d4 +beq no_swap +bge swap +bra no_swap + +swap: +load 0 2 d1 +load 1 2 d2 +store 0 2 d2 +store 1 2 d1 + +; lista_sorterad = 0 +load 0 1 +0000 +store 0 0 d0 + +no_swap: +; räkna upp addr +load 0 0 d1 +add 0 1 +0001 +store 0 0 d1 + +; addr = 0xff? +load 0 0 d1 +cmp 0 1 +00ff +bne label2 + +; lista_sorterad = 1? +load 0 0 d0 +cmp 0 1 +0001 +bne label1 + +halt diff --git a/lab1/lab1-upg3.mia b/lab1/lab1-upg3.mia new file mode 100644 index 0000000..e095eca --- /dev/null +++ b/lab1/lab1-upg3.mia @@ -0,0 +1,458 @@ +PM: +00: 0100 +01: 0001 +02: 10d0 +03: 0100 +04: 00e0 +05: 10d1 +06: 02d1 +07: 10d3 +08: 00d1 +09: 2100 +0a: 0001 +0b: 10d2 +0c: 02d2 +0d: 10d4 +0e: 00d3 +0f: 90d4 +10: b009 +11: a001 +12: 6007 +13: 02d1 +14: 06d2 +15: 12d2 +16: 16d1 +17: 0100 +18: 0000 +19: 10d0 +1a: 00d1 +1b: 2100 +1c: 0001 +1d: 10d1 +1e: 00d1 +1f: 9100 +20: 00ff +21: 70e4 +22: 00d0 +23: 9100 +24: 0001 +25: 70da +26: 8000 +27: 0000 +28: 0000 +29: 0000 +2a: 0000 +2b: 0000 +2c: 0000 +2d: 0000 +2e: 0000 +2f: 0000 +30: 0000 +31: 0000 +32: 0000 +33: 0000 +34: 0000 +35: 0000 +36: 0000 +37: 0000 +38: 0000 +39: 0000 +3a: 0000 +3b: 0000 +3c: 0000 +3d: 0000 +3e: 0000 +3f: 0000 +40: 0000 +41: 0000 +42: 0000 +43: 0000 +44: 0000 +45: 0000 +46: 0000 +47: 0000 +48: 0000 +49: 0000 +4a: 0000 +4b: 0000 +4c: 0000 +4d: 0000 +4e: 0000 +4f: 0000 +50: 0000 +51: 0000 +52: 0000 +53: 0000 +54: 0000 +55: 0000 +56: 0000 +57: 0000 +58: 0000 +59: 0000 +5a: 0000 +5b: 0000 +5c: 0000 +5d: 0000 +5e: 0000 +5f: 0000 +60: 0000 +61: 0000 +62: 0000 +63: 0000 +64: 0000 +65: 0000 +66: 0000 +67: 0000 +68: 0000 +69: 0000 +6a: 0000 +6b: 0000 +6c: 0000 +6d: 0000 +6e: 0000 +6f: 0000 +70: 0000 +71: 0000 +72: 0000 +73: 0000 +74: 0000 +75: 0000 +76: 0000 +77: 0000 +78: 0000 +79: 0000 +7a: 0000 +7b: 0000 +7c: 0000 +7d: 0000 +7e: 0000 +7f: 0000 +80: 0000 +81: 0000 +82: 0000 +83: 0000 +84: 0000 +85: 0000 +86: 0000 +87: 0000 +88: 0000 +89: 0000 +8a: 0000 +8b: 0000 +8c: 0000 +8d: 0000 +8e: 0000 +8f: 0000 +90: 0000 +91: 0000 +92: 0000 +93: 0000 +94: 0000 +95: 0000 +96: 0000 +97: 0000 +98: 0000 +99: 0000 +9a: 0000 +9b: 0000 +9c: 0000 +9d: 0000 +9e: 0000 +9f: 0000 +a0: 0000 +a1: 0000 +a2: 0000 +a3: 0000 +a4: 0000 +a5: 0000 +a6: 0000 +a7: 0000 +a8: 0000 +a9: 0000 +aa: 0000 +ab: 0000 +ac: 0000 +ad: 0000 +ae: 0000 +af: 0000 +b0: 0000 +b1: 0000 +b2: 0000 +b3: 0000 +b4: 0000 +b5: 0000 +b6: 0000 +b7: 0000 +b8: 0000 +b9: 0000 +ba: 0000 +bb: 0000 +bc: 0000 +bd: 0000 +be: 0000 +bf: 0000 +c0: 0000 +c1: 0000 +c2: 0000 +c3: 0000 +c4: 0000 +c5: 0000 +c6: 0000 +c7: 0000 +c8: 0000 +c9: 0000 +ca: 0000 +cb: 0000 +cc: 0000 +cd: 0000 +ce: 0000 +cf: 0000 +d0: 0000 +d1: 0000 +d2: 0000 +d3: 0000 +d4: 0000 +d5: 0000 +d6: 0000 +d7: 0000 +d8: 0000 +d9: 0000 +da: 0000 +db: 0000 +dc: 0000 +dd: 0000 +de: 0000 +df: 0000 +e0: 0000 +e1: 0000 +e2: 0000 +e3: 0000 +e4: 0000 +e5: 0000 +e6: 0000 +e7: 0000 +e8: 0000 +e9: 0000 +ea: 0000 +eb: 0000 +ec: 0000 +ed: 0000 +ee: 0000 +ef: 0000 +f0: 0000 +f1: 0000 +f2: 0000 +f3: 0000 +f4: 0000 +f5: 0000 +f6: 0000 +f7: 0000 +f8: 0000 +f9: 0000 +fa: 0000 +fb: 0000 +fc: 0000 +fd: 0000 +fe: 0000 +ff: 0000 + +MyM: +00: 00f8000 +01: 0088000 +02: 0002000 +03: 0000100 +04: 0078000 +05: 0000080 +06: 00f8000 +07: 0002000 +08: 0000080 +09: 0078000 +0a: 00b8000 +0b: 0000080 +0c: 0240000 +0d: 1184000 +0e: 0138000 +0f: 0000080 +10: 00b0000 +11: 0000180 +12: 0190000 +13: 0000180 +14: 0280000 +15: 0980000 +16: 0130000 +17: 0000180 +18: 0380000 +19: 0a80000 +1a: 0130000 +1b: 0000180 +1c: 0380000 +1d: 0c80000 +1e: 0130000 +1f: 0000180 +20: 0380000 +21: 0081000 +22: 0000626 +23: 0000800 +24: 1a00000 +25: 0000322 +26: 0130000 +27: 0000180 +28: 02c0000 +29: 1040000 +2a: 0118000 +2b: 0000180 +2c: 02c0000 +2d: 000042f +2e: 1040000 +2f: 0118000 +30: 0000180 +31: 0000780 +32: 0380000 +33: 0a80000 +34: 0000180 +35: 02c0000 +36: 00004b9 +37: 00005bc +38: 000033b +39: 00005bb +3a: 000033c +3b: 1040000 +3c: 0118000 +3d: 0000180 +3e: 02c0000 +3f: 0000441 +40: 0000342 +41: 1040000 +42: 0118000 +43: 0000180 +44: 0000344 +45: 0000000 +46: 0000000 +47: 0000000 +48: 0000000 +49: 0000000 +4a: 0000000 +4b: 0000000 +4c: 0000000 +4d: 0000000 +4e: 0000000 +4f: 0000000 +50: 0000000 +51: 0000000 +52: 0000000 +53: 0000000 +54: 0000000 +55: 0000000 +56: 0000000 +57: 0000000 +58: 0000000 +59: 0000000 +5a: 0000000 +5b: 0000000 +5c: 0000000 +5d: 0000000 +5e: 0000000 +5f: 0000000 +60: 0000000 +61: 0000000 +62: 0000000 +63: 0000000 +64: 0000000 +65: 0000000 +66: 0000000 +67: 0000000 +68: 0000000 +69: 0000000 +6a: 0000000 +6b: 0000000 +6c: 0000000 +6d: 0000000 +6e: 0000000 +6f: 0000000 +70: 0000000 +71: 0000000 +72: 0000000 +73: 0000000 +74: 0000000 +75: 0000000 +76: 0000000 +77: 0000000 +78: 0000000 +79: 0000000 +7a: 0000000 +7b: 0000000 +7c: 0000000 +7d: 0000000 +7e: 0000000 +7f: 0000000 + +K1: +00: 10 +01: 12 +02: 14 +03: 18 +04: 1c +05: 20 +06: 28 +07: 2c +08: 31 +09: 32 +0a: 35 +0b: 3e +0c: 00 +0d: 00 +0e: 00 +0f: 00 + +K2: +00: 04 +01: 06 +02: 09 +03: 0c + +PC: +00 + +ASR: +00 + +AR: +0000 + +HR: +0000 + +GR0: +0000 + +GR1: +0000 + +GR2: +0000 + +GR3: +0000 + +IR: +0000 + +MyPC: +00 + +SMyPC: +00 + +LC: +00 + +O_flag: + +C_flag: + +N_flag: + +Z_flag: + +L_flag: +End_of_dump_file diff --git a/lab1/lab1asm.py b/lab1/lab1asm.py new file mode 100644 index 0000000..ce1df5e --- /dev/null +++ b/lab1/lab1asm.py @@ -0,0 +1,79 @@ +import sys + +OPS = { + "load": 0, + "store": 1, + "add": 2, + "sub": 3, + "and": 4, + "lsr": 5, + "bra": 6, + "bne": 7, + "halt": 8, + "cmp": 9, + "bge": 10, + "beq": 11, +} + +def compile(lines): + addr = 0 + labels = {} + compiled = [] + for line in lines: + if not line: + # empty line, ignore + continue + if line.startswith(";"): + # comment + continue + if line.endswith(":"): + # label + labels[line.split(":")[0]] = addr + continue + match line.split(" "): + case [inst, gr, m, *adr]: + if int(m) == 1: + assert adr == [] + compiled.append("{:02x}: {:01x}{:01x}{:02x}".format( + addr, + OPS[inst], + int(gr) * 4 + int(m), + int(adr[0], 16) if int(m) != 1 else 0, + )) + case [inst, label]: + assert inst in ("bra", "bne", "bge", "beq") + compiled.append("{:02x}: {:01x}0<{}>".format( + addr, + OPS[inst], + label, + )) + case ["halt"]: + compiled.append("{:02x}: {:01x}000".format(addr, OPS["halt"])) + case [oper]: + compiled.append("{:02x}: {:04x}".format(addr, int(oper, 16))) + case _: + compiled.append(" !!!", line) + assert False + addr += 1 + + linked = [] + for line_nr, line in enumerate(compiled): + for label, label_nr in labels.items(): + rel_pos = (label_nr - line_nr + 0xff) & 0xff + line = line.replace(f"<{label}>", f"{rel_pos:02x}") + linked.append(line) + + return linked, labels + + +def write(prog, labels): + prog_pad = 0x100 - len(prog) + prog = "\n".join(prog + [f"{len(prog)+n:02x}: 0000" for n in range(prog_pad)]) + + print("PM:") + print(prog) + #print("\n".join(["{}: {:02x}".format(*label) for label in labels.items()]), file=sys.stderr) + + +if __name__ == "__main__": + write(*compile([line.strip() for line in sys.stdin])) diff --git a/lab1/lab1ucode.in b/lab1/lab1ucode.in new file mode 100644 index 0000000..d0a65f9 --- /dev/null +++ b/lab1/lab1ucode.in @@ -0,0 +1,95 @@ +pc->asr +pm->ir, pc++ +k2->upc + +direct: +ir->asr, k1->upc + +immediate: +pc->asr, pc++, k1->upc + +indirect: +ir->asr +pm->asr, k1->upc + +indexed: +ir->ar +; ar+gr3->ar +!1184000 +ar->asr, k1->upc + +load: +pm->grx, 0->upc + +store: +grx->pm, 0->upc + +add: +pm->ar +ar+grx->ar +ar->grx, 0->upc + +sub: +grx->ar +ar-pm->ar +ar->grx, 0->upc + +and: +grx->ar +ar&pm->ar +ar->grx, 0->upc + +lsr: +grx->ar +pm->lc +lsr_loop: +l=1? lsr_exit +lc--, lsr, b lsr_loop +lsr_exit: +ar->grx, 0->upc + +bra: +pc->ar +ar+'ir->ar +ar->pc, 0->upc + +bne: +pc->ar +z=1? bne_done +ar+'ir->ar +bne_done: +ar->pc, 0->upc + +halt: +halt + +cmp: +grx->ar +ar-pm->ar, 0->upc + +bge: +pc->ar +; if grx < pm +n=1? checko1 +o=1? bge_done +; N, N -> yes +b bge_jump +checko1: +o=1? bge_jump +b bge_done +bge_jump: +ar+'ir->ar +bge_done: +ar->pc, 0->upc + +beq: +pc->ar +z=1? beq_yes +b beq_no +beq_yes: +ar+'ir->ar +beq_no: +ar->pc, 0->upc + +end: +b end diff --git a/lab1/lab1ucode.py b/lab1/lab1ucode.py new file mode 100644 index 0000000..cc8c94c --- /dev/null +++ b/lab1/lab1ucode.py @@ -0,0 +1,198 @@ +import sys + +from string import Template + +TWOWAY = { + "ir": "001", + "pm": "010", + "pc": "011", + "hr": "101", + "grx": "110", +} + +# to bus: source +TB = TWOWAY | { + "ar": "100", + # "styrord": "111", +} + +# from bus: destination +FB = TWOWAY | { + "asr": "111" +} + +def compile(lines): + addr = 0 + labels = {} + compiled = [] + todo = [] + for line in lines: + if not line: + # empty line, ignore + continue + if line.startswith(";"): + # comment + continue + if line.endswith(":"): + # label + labels[line.split(":")[0]] = addr + continue + if line.startswith("!"): + # inline + compiled.append(line[1:]) + addr += 1 + continue + + for inst in line.split(", "): + alu = "0000" + tb = "000" + fb = "000" + s = "0" + p = "0" + lc = "00" + seq = "0000" + myadr = "0000000" + + if "->" in inst: + # move a value + fr, to = inst.split("->") + # via bus + if fr in TB: + tb = TB[fr] + if to in FB: + fb = FB[to] + + if "gr" in fr and len(fr) == 3: + tb = TB["grx"] + if "gr" in to and len(to) == 3: + fb = FB["grx"] + + if to == "lc": + lc = "10" + + # load alu + if to == "ar": + alu = "0001" + + # alu addition + if "+" in fr: + if "+'" in fr: + # ignore flags + other = fr.split("+'")[1] + alu = "1000" + else: + other = fr.split("+")[1] + alu = "0100" + tb = TB[other] + + # alu subtraction + if "-" in fr: + other = fr.split("-")[1] + tb = TB[other] + alu = "0101" + + if "&" in fr: + other = fr.split("&")[1] + tb = TB[other] + alu = "0110" + + if inst == "pc++": + p = "1" + + if inst == "k1->upc": + seq = "0001" + if inst == "k2->upc": + seq = "0010" + if inst == "0->upc": + seq = "0011" + if inst == "halt": + seq = "1111" + if inst == "lc--": + lc = "01" + if inst == "lsr": + alu = "1101" + + if "?" in inst: + cond, to = inst.split("? ") + if cond == "l=1": + seq = "1100" + elif cond == "z=1": + seq = "1000" + elif cond == "n=1": + seq = "1001" + elif cond == "o=1": + seq = "1011" + else: + assert False + myadr = f"<{to}>" + + if inst.startswith("b "): + seq = "0110" #TODO 0101? + myadr = "<{}>".format(inst.split("b ")[1]) + + compiled.append((inst, (alu, tb, fb, s, p, lc, seq, myadr))) + + addr += 1 + + linked = [] + for addr, line in enumerate(compiled): + if type(line) is str: + linked.append((addr, line)) + continue + inst, (alu, tb, fb, s, p, lc, seq, myadr) = line + if myadr != "0000000": + for label, label_line in labels.items(): + myadr = myadr.replace(f"<{label}>", str(bin(label_line)[2:]).zfill(7)) + first = alu[0] + rest = alu[1:] + tb + fb + s + p + lc + seq + myadr + hs = "".join([f"{int(first):01x}"] + [f"{int(rest[i:i+4], 2):01x}" for i in range(0, len(rest), 4)]) + linked.append((addr, hs)) + if hs == "0000000": + todo.append(inst) + + if todo: + print("todo", file=sys.stderr) + print("\n".join(todo), file=sys.stderr) + assert False + + return ["{:02x}: {}".format(addr, line) for addr, line in linked], labels + + +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_pad = 0x10 - len(insts) + inst_locations = "\n".join([f"{i:02x}: {labels[inst]:02x}" for i, inst in enumerate(insts)] + + [f"{n+len(insts):02x}: 00" for n in range(inst_pad)]) + + print("MyM:") + print(ucode) + print() + + print("K1:") + print(inst_locations) + #print(template.safe_substitute(pm)) + + print("K2:") + + +if __name__ == "__main__": + write(*compile([line.strip() for line in sys.stdin])) diff --git a/lab1/todo b/lab1/todo new file mode 100644 index 0000000..4471101 --- /dev/null +++ b/lab1/todo @@ -0,0 +1,8 @@ +push/pop + use grx as stack pointer + assembly makes sure nothing uses chosen grx (probably gr2) +jsr,rst + using the stack +check cmp order +bge doesn't work +bne probably not needed. beq enough |
