summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2023-06-12 23:16:50 -0400
committerTest_User <hax@andrewyu.org>2023-06-12 23:16:50 -0400
commit8dfea072b94d595370bb5bb7924a1bf61779810b (patch)
treeea192dfa3796941fa05f853f998b914aa2bb71f2
parent436b5d8c70d12ade24eaad252f0e96ffad969ffe (diff)
downloaddevelopment-8dfea072b94d595370bb5bb7924a1bf61779810b.tar.gz
development-8dfea072b94d595370bb5bb7924a1bf61779810b.zip
Change instruction format a bit, continue assembler writing
-rw-r--r--assembler/arbitrary_constants.py22
-rwxr-xr-xassembler/hasm.py11
2 files changed, 31 insertions, 2 deletions
diff --git a/assembler/arbitrary_constants.py b/assembler/arbitrary_constants.py
new file mode 100644
index 0000000..88c0722
--- /dev/null
+++ b/assembler/arbitrary_constants.py
@@ -0,0 +1,22 @@
+# These numbers don't change behavior much and aren't specified yet, but there being a number is required
+
+max_immediate_value_size = 64
+immediate_bit_size = math.ceil(math.log2(max_immediate_value_size))
+
+num_registers = 16
+
+# Likely won't be limited quite like this, but this still works
+max_types_per_queue = 16
+max_instructions_per_type = 16
+
+num_instructions_bit_size = math.ceil(math.log2(max_instructions_per_type))
+
+print("Bits to declare instruction count per opcode:", num_instructions_bit_size)
+
+max_parameters_per_instruction = 0
+for name in instructions:
+ if instructions[name]['params'] > max_parameters_per_instruction:
+ max_parameters_per_instruction = instructions[name]['params']
+
+max_parameters_per_instruction += 2 # conditional
+
diff --git a/assembler/hasm.py b/assembler/hasm.py
index 1cb924b..fcac8c9 100755
--- a/assembler/hasm.py
+++ b/assembler/hasm.py
@@ -7,7 +7,9 @@ import glob
import os
import sys
-datadir = os.path.abspath(os.path.dirname(__file__)+"/../cpu")
+thisdir = os.path.abspath(os.path.dirname(__file__))
+
+datadir = os.path.abspath(thisdir+"/../cpu")
paths = glob.glob(datadir+"/instructions/*/*")
@@ -44,9 +46,14 @@ for ins in instructions:
print("Opcodes:", instructions)
print("Opcode count:", num_instructions)
-instruction_bit_size = math.ceil(math.log2(num_instructions))
+instruction_bit_size = math.ceil(math.log2(num_instructions)) + 1 # + 1 for is_conditional
print("Bits per opcode:", instruction_bit_size)
+# do this after reading the config
+f = open(thisdir+"/arbitrary_constants.py");
+exec(f.read())
+f.close()
+
argc = len(sys.argv)
print("Number of args given:", argc)