SAPsim package

Subpackages

Module contents

Simulation of SAP (Simple As Possible) computer programs from COMP311 (Computer Organization) @ UNC.

Defines run() and create_template().

SAPsim.create_template(path: str = 'template.csv') None[source]

Create blank template file in SAPsim format in current directory.

Parameters:

path (str) – Path to create template file at. Defaults to template.csv.

Returns:

None

SAPsim.run(prog_path: str, **kwargs) None | dict[str, Any][source]

Run given .csv program in SAPsim format.

Parameters:
  • prog_path (str) – .csv file in SAPsim format.

  • **kwargs – See below

Keyword Arguments:
  • debug (bool) –
    • Whether to run in debug mode (True) or at full speed (False)

    • Default is full speed

  • change (dict[int, int]) –
    • dict[address, byte] of values to change in RAM

    • The value at each address (0 to 15) will be overwritten to that byte

    • Useful for debugging programs (edit a value without changing the CSV)

    • Useful for autograding programs (overwrite a reserved instruction/data value)

  • table_format (str) –
  • The rest of the parameters are pretty much exclusively for unit testing, and you should not use these
    • return_state (bool) –
      • If True, then program state will be returned

      • See utils.helpers.get_state()

      • Will probably cause type warnings since the return type is Union[None, dict[str, Any]]

      • To avoid type warnings, use run_and_return_state

    • non_blocking (bool) –
      • This is used to unit test debug mode of run(), you likely don’t have a need for this

      • If True, then run() won’t block on input

      • input() won’t be called in debug mode (i.e., don’t have to press enter to continue execution)

      • If this is True, then debug mode will be on even if debug isn’t in kwargs

    • no_print (bool) –
      • This is used to save computation time during unit testing

      • If True, then print_RAM() and print_info() won’t be called

      • In debug mode, “Program halted.” will still be printed

    • bits (int) –
      • You should not modify this

      • Number of bits in registers

      • Default value in global_vars is 8

      • 8 is also the maximum value since everything in RAM should fit in a byte

Returns:

None or program state if return_state

Return type:

Union[None, dict[str, Any]]

SAPsim.run_and_return_state(prog_path: str, **kwargs) dict[str, Any][source]

Run given .csv program in SAPsim format.

Parameters:
  • prog_path (str) – .csv file in SAPsim format.

  • **kwargs – See below

Keyword Arguments:
  • debug (bool) –
    • Whether to run in debug mode (True) or at full speed (False)

    • Default is full speed

  • change (dict[int, int]) –
    • dict[address, byte] of values to change in RAM

    • The value at each address (0 to 15) will be overwritten to that byte

    • Useful for debugging programs (edit a value without changing the CSV)

    • Useful for autograding programs (overwrite a reserved instruction/data value)

  • table_format (str) –
  • The rest of the parameters are pretty much exclusively for unit testing, and you should not use these
    • return_state (bool) –
      • If True, then program state will be returned

      • See utils.helpers.get_state()

      • Will probably cause type warnings since the return type is Union[None, dict[str, Any]]

      • To avoid type warnings, use run_and_return_state

    • non_blocking (bool) –
      • This is used to unit test debug mode of run(), you likely don’t have a need for this

      • If True, then run() won’t block on input

      • input() won’t be called in debug mode (i.e., don’t have to press enter to continue execution)

      • If this is True, then debug mode will be on even if debug isn’t in kwargs

    • no_print (bool) –
      • This is used to save computation time during unit testing

      • If True, then print_RAM() and print_info() won’t be called

      • In debug mode, “Program halted.” will still be printed

    • bits (int) –
      • You should not modify this

      • Number of bits in registers

      • Default value in global_vars is 8

      • 8 is also the maximum value since everything in RAM should fit in a byte

Returns:

None or program state if return_state

Returns:

dict containing program state (see helpers.get_state)

Return type:

dict[str, Any]