summaryrefslogtreecommitdiffstats
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
parent35f34d203f2720503bea92e1bcbca49bea4b16a9 (diff)
downloadtsea83-049f91d8c7224062a8ad3ca316bc8454c9d15944.tar.gz
gen k1
-rw-r--r--lab1-2.mia38
-rw-r--r--lab1asm.py16
-rw-r--r--lab1ucode.in5
-rw-r--r--lab1ucode.out128
-rw-r--r--lab1ucode.py47
-rw-r--r--lab1upg2.out234
-rw-r--r--lab1upg3.out220
-rw-r--r--template.mia62
8 files changed, 672 insertions, 78 deletions
diff --git a/lab1-2.mia b/lab1-2.mia
index 06fcb7c..a32a38d 100644
--- a/lab1-2.mia
+++ b/lab1-2.mia
@@ -297,20 +297,20 @@ MyM:
25: 0000322
26: 0130000
27: 0000180
-28: 0000180
-29: 0000180
-2a: 0000780
-2b: 0280000
-2c: 0b80000
+28: 00f8000
+29: 0280000
+2a: 0002000
+2b: 08c0000
+2c: 0118000
2d: 0000180
2e: 0000180
-2f: 0000180
-30: 0000330
-31: 0000000
-32: 0000000
-33: 0000000
-34: 0000000
-35: 0000000
+2f: 0000780
+30: 0280000
+31: 0b80000
+32: 0000180
+33: 0000180
+34: 0000180
+35: 0000335
36: 0000000
37: 0000000
38: 0000000
@@ -394,15 +394,11 @@ K1:
04: 1c
05: 20
06: 28
-07: 29
-08: 2a
-09: 2b
-0a: 2e
-0b: 2f
-0c: 00
-0d: 00
-0e: 00
-0f: 00
+07: 2e
+08: 2f
+09: 30
+0a: 33
+0b: 34
K2:
00: 04
diff --git a/lab1asm.py b/lab1asm.py
index 6f09bff..dfe9fb3 100644
--- a/lab1asm.py
+++ b/lab1asm.py
@@ -69,11 +69,13 @@ def compile(lines):
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)
+
+
if __name__ == "__main__":
- prog, labels = compile([line.strip() for line in sys.stdin])
- print("prog:")
- print("\n".join(prog))
- print()
- print("labels:")
- for label, label_nr in labels.items():
- print(label, hex(label_nr))
+ write(*compile([line.strip() for line in sys.stdin]))
diff --git a/lab1ucode.in b/lab1ucode.in
index b95a965..34597a5 100644
--- a/lab1ucode.in
+++ b/lab1ucode.in
@@ -49,7 +49,10 @@ lsr_exit:
ar->grx, 0->upc
bra:
-0->upc
+pc->asr
+pm->ar, pc++
+ar+pc->ar
+ar->pc, 0->upc
bne:
0->upc
diff --git a/lab1ucode.out b/lab1ucode.out
index 51f0a52..fa1ace1 100644
--- a/lab1ucode.out
+++ b/lab1ucode.out
@@ -1,4 +1,4 @@
-prog:
+MyM:
00: 00f8000
01: 0088000
02: 0002000
@@ -39,33 +39,105 @@ prog:
25: 0000322
26: 0130000
27: 0000180
-28: 0000180
-29: 0000180
-2a: 0000780
-2b: 0280000
-2c: 0b80000
+28: 00f8000
+29: 0280000
+2a: 0002000
+2b: 08c0000
+2c: 0118000
2d: 0000180
2e: 0000180
-2f: 0000180
-30: 0000330
+2f: 0000780
+30: 0280000
+31: 0b80000
+32: 0000180
+33: 0000180
+34: 0000180
+35: 0000335
+36: 0000000
+37: 0000000
+38: 0000000
+39: 0000000
+3a: 0000000
+3b: 0000000
+3c: 0000000
+3d: 0000000
+3e: 0000000
+3f: 0000000
+40: 0000000
+41: 0000000
+42: 0000000
+43: 0000000
+44: 0000000
+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
-labels:
-direct 0x4
-immediate 0x6
-indirect 0x9
-indexed 0xc
-load 0x10
-store 0x12
-add 0x14
-sub 0x18
-and 0x1c
-lsr 0x20
-lsr_loop 0x22
-lsr_exit 0x26
-bra 0x28
-bne 0x29
-halt 0x2a
-cmp 0x2b
-bge 0x2e
-beq 0x2f
-end 0x30
+K1:
+00: 10
+01: 12
+02: 14
+03: 18
+04: 1c
+05: 20
+06: 28
+07: 2e
+08: 2f
+09: 30
+0a: 33
+0b: 34
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]))
diff --git a/lab1upg2.out b/lab1upg2.out
index a155f52..a95fda0 100644
--- a/lab1upg2.out
+++ b/lab1upg2.out
@@ -1,4 +1,4 @@
-prog:
+PM:
00: 00fe
01: 4100
02: 000f
@@ -25,5 +25,233 @@ prog:
17: 20ff
18: 10ff
19: 8000
-
-labels:
+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
diff --git a/lab1upg3.out b/lab1upg3.out
index 5dfe4fb..c73d404 100644
--- a/lab1upg3.out
+++ b/lab1upg3.out
@@ -1,4 +1,4 @@
-prog:
+PM:
00: 0100
01: 0001
02: 10d0
@@ -43,9 +43,215 @@ prog:
29: 7000
2a: -02a
2b: 8000
-
-labels:
-label1 0x0
-label2 0x6
-swap 0x16
-no_swap 0x1d
+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
diff --git a/template.mia b/template.mia
new file mode 100644
index 0000000..7acc46e
--- /dev/null
+++ b/template.mia
@@ -0,0 +1,62 @@
+PM:
+$pm
+00..ff
+
+MyM:
+$my_m
+00..7f
+
+K1:
+$k1
+00..0f
+
+K2:
+$k2
+00..03
+
+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