summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2023-06-14 03:19:05 -0400
committerTest_User <hax@andrewyu.org>2023-06-14 03:19:05 -0400
commit4602f3cb8b2f00abdef7c739847828b0025a492a (patch)
tree276b412aa364ce6d55c1fc0774ea6c2c5f111b71
parent8dfea072b94d595370bb5bb7924a1bf61779810b (diff)
downloaddevelopment-4602f3cb8b2f00abdef7c739847828b0025a492a.tar.gz
development-4602f3cb8b2f00abdef7c739847828b0025a492a.zip
Bit of change to parameters, and fixing it to actually say what I meant; more assembler progress as well
-rw-r--r--assembler/arbitrary_constants.py56
-rwxr-xr-xassembler/hasm.py9
-rw-r--r--assembler/syntax.txt2
3 files changed, 61 insertions, 6 deletions
diff --git a/assembler/arbitrary_constants.py b/assembler/arbitrary_constants.py
index 88c0722..058f00a 100644
--- a/assembler/arbitrary_constants.py
+++ b/assembler/arbitrary_constants.py
@@ -3,7 +3,45 @@
max_immediate_value_size = 64
immediate_bit_size = math.ceil(math.log2(max_immediate_value_size))
-num_registers = 16
+num_general_registers = 16
+num_segment_registers = 8
+
+num_special_registers = 4 + 2 + 6 + 3
+# MR,PR,FR,OFR + RS,RW + O{IP,PR}{H,E,DE} + IP,SP,BP
+
+num_registers = num_general_registers + num_segment_registers + num_special_registers
+bits_for_register_selection = math.ceil(math.log2(num_registers))
+
+print("Number of different registers (total):", num_registers)
+print("Bits required to specify which of them:", bits_for_register_selection)
+
+# this value will eventually be a part of the assembly language itself and not a constant here
+
+current_mode = 128
+
+print("Assembling for mode:", current_mode)
+
+bits_for_current_mode = math.log2(current_mode)
+if bits_for_current_mode//1 != bits_for_current_mode:
+ print("¦|") # this isn't a valid mode for HaxCPU
+ os._exit(1)
+
+bits_for_each_mode_value = math.ceil(math.log2(bits_for_current_mode))
+
+print("Bits required for showing each power of 2 value <= current mode:", bits_for_each_mode_value)
+
+parameter_data_bits = bits_for_each_mode_value + max(immediate_bit_size, bits_for_register_selection) + bits_for_each_mode_value
+
+print("Bits available for a parameter's data:", parameter_data_bits)
+
+num_param_types = 5
+bits_for_parameter_type = math.ceil(math.log2(num_param_types))
+
+print("Bits taken to state which parameter type this is:", bits_for_parameter_type)
+
+bits_per_parameter = parameter_data_bits + bits_for_parameter_type
+
+print("Bits per parameter:", bits_per_parameter)
# Likely won't be limited quite like this, but this still works
max_types_per_queue = 16
@@ -20,3 +58,19 @@ for name in instructions:
max_parameters_per_instruction += 2 # conditional
+print("Max parameters any instruction will take:", max_parameters_per_instruction)
+
+max_instruction_queue_size = (max_types_per_queue * (opcode_bit_size + num_instructions_bit_size + (bits_per_parameter * max_parameters_per_instruction * max_instructions_per_type)))
+
+print("Max size of the instruction part of the queue:", max_instruction_queue_size)
+
+size_instruction_queue_bits = math.ceil(math.log2(max_instruction_queue_size))
+
+print("Bits taken to state instruction queue size:", size_instruction_queue_bits)
+
+# Can be lower, but makes no sense to go over
+# Currently not actually used other than for instruction queue size bc I haven't written it into the assembly syntax yet
+# Will have to do that to make it very useful... but just to get it working first
+max_flag_save_definitions = max_types_per_queue * max_instructions_per_type
+
+bits_for_flag_save_definition_size = math.ceil(math.log2(max_flag_save_definitions))
diff --git a/assembler/hasm.py b/assembler/hasm.py
index fcac8c9..d9f33b2 100755
--- a/assembler/hasm.py
+++ b/assembler/hasm.py
@@ -46,8 +46,8 @@ for ins in instructions:
print("Opcodes:", instructions)
print("Opcode count:", num_instructions)
-instruction_bit_size = math.ceil(math.log2(num_instructions)) + 1 # + 1 for is_conditional
-print("Bits per opcode:", instruction_bit_size)
+opcode_bit_size = math.ceil(math.log2(num_instructions)) + 1 # + 1 for is_conditional
+print("Bits per opcode:", opcode_bit_size)
# do this after reading the config
f = open(thisdir+"/arbitrary_constants.py");
@@ -78,7 +78,7 @@ inputf.close()
print(input)
-# first pass: evaluate instructions, calculate sizes, validate syntax
+# first pass: evaluate instructions, calculate sizes, validate syntax, evaluate label addresses
linenum = 0
in_queue = False
last_queue_opcode = None
@@ -99,5 +99,4 @@ for line in input.split('\n'):
print(line[0:i])
-# second pass: calculate label addresses
-# third pass: evaluate parameter values, create binary output
+# second pass: evaluate parameter values, create binary output
diff --git a/assembler/syntax.txt b/assembler/syntax.txt
index fb1af1a..1eaf91c 100644
--- a/assembler/syntax.txt
+++ b/assembler/syntax.txt
@@ -22,6 +22,8 @@ Instruction queues are surrounded by { and }:
{ and } must be on their own in the line (aside for whitespace and comments)
+If a parameter (and just the parameter) is placed between [ and ], it will be considered an indirect reference; the memory pointed to by that will be used
+
If an instruction is specified without { and }, it is considered to be an instruction queue of only that instruction
Labels are any combination of non-whitespace non-quotation from the start of the line to a ':', and not followed by any non-comment non-whitespace