eight_bit_computer.operation_utils module

Common functions for operations.

eight_bit_computer.operation_utils.assemble_instruction(instruction_bitdefs, flags_bitdefs, control_steps)[source]

Create templates for all steps to form a complete instruction.

Parameters:
  • instruction_bitdefs (list(str)) – List of the bitdefs that make up the instruction byte.
  • flags_bitdefs – list(str): List of the bitdefs that make up the flags for this instruction.
  • control_steps – list(list(str): List of list of bitdefs that make up the control signals for each step.
Returns:

All the steps for this instruction.

Return type:

list(DataTemplate)

Raises:

ValueError – If too many steps were provided.

eight_bit_computer.operation_utils.add_quotes_to_strings(strings)[source]

Add double quotes strings in a list then join with commas.

Parameters:strings (list(str)) – List of strings to add parentheses to.
Returns:The strings with quotes added and joined with commas.
Return type:str
eight_bit_computer.operation_utils.match_and_parse_line(line, opcode, signatures=None)[source]

Examine assembly code to see if it is valid and parse the arguments.

This is a common function used by most of the assembly operations.

Parameters:
  • line (str) – The line of assembly code.
  • opcode (str) – The opcode this line is being tested to match.
  • signatures (list(list(dict)), optional) – Data structure that defines the different combinations of arguments. See get_arg_def_template() for more details.
Returns:

Whether or not the line matched, and if it did, the parsed arguments.

Return type:

(bool, list(dict))

Raises:
  • OperationParsingError – If multiple op_args defs matched. Or
  • if no op_args defs matched if the opcode matched (i.e. the
  • arguments weren’t valid for that assembly operation).
eight_bit_computer.operation_utils.generate_possible_signatures_list(signatures)[source]

Create a readable list of all possible signatures.

Parameters:signatures (list(list(dict))) – Data structure that defines the different combinations of arguments. See get_arg_def_template() for more details.
Returns:All possible argument combinations.
Return type:list(str)
eight_bit_computer.operation_utils.match_and_parse_args(line_args, signature)[source]

Parse assembly operation args if they match the definition.

Take arguments supplied for the assembly operation and see if they match this arguments definition.

Parameters:
  • line_args – (list(str)): The arguments supplied for this assembly operation.
  • signature (list(dict)) – Definition of a set of arguments. See get_arg_def_template() for more details.
Returns:

Whether or not the arguments matched, and if they did, the parsed values.

Return type:

(bool, list(dict))

Raises:

OperationParsingError – If a single argument managed to match different kinds of argument definitions.