From 8dfea072b94d595370bb5bb7924a1bf61779810b Mon Sep 17 00:00:00 2001 From: Test_User Date: Mon, 12 Jun 2023 23:16:50 -0400 Subject: Change instruction format a bit, continue assembler writing --- assembler/arbitrary_constants.py | 22 ++++++++++++++++++++++ assembler/hasm.py | 11 +++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 assembler/arbitrary_constants.py 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) -- cgit v1.2.3