SAPsim package
Subpackages
- SAPsim.utils package
- Submodules
- SAPsim.utils.exceptions module
ARegisterNegativeIntARegisterNotEnoughBitsBRegisterNegativeIntBRegisterNotEnoughBitsChangeAddressGreaterThan15ChangeAddressNegativeChangeValueInvalidDroppedOffBottomDuplicateAddressFileNotCSVFirstHexitGreaterThan15FirstHexitNegativeInstructionRequiresArgInvalidAddressInvalidFirstHexitInvalidInstructionStringInvalidSecondHexitJumpToNegativeAddressLoadFromUnmappedAddressMoreThan16MappedAddressesNegativeAddressNoFirstHexitNoSecondHexitNonNumericalAddressRowWithNoAddressSecondHexitGreaterThan15SecondHexitNegativeprint_debug_info()
- SAPsim.utils.execute module
- SAPsim.utils.global_vars module
- SAPsim.utils.helpers module
- SAPsim.utils.instructions module
- SAPsim.utils.parser module
- Module contents
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
- debug (
- 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)
- change (
- table_format (
str) – Printed table format
Options: https://github.com/astanin/python-tabulate#table-format
Default value in
global_varsis"simple_outline"
- table_format (
- 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 returnedSee
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
- return_state (
- non_blocking (
bool) – This is used to unit test debug mode of
run(), you likely don’t have a need for thisIf
True, thenrun()won’t block on inputinput()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 ifdebugisn’t in kwargs
- non_blocking (
- no_print (
bool) – This is used to save computation time during unit testing
If
True, thenprint_RAM()andprint_info()won’t be calledIn debug mode, “Program halted.” will still be printed
- no_print (
- bits (
int) – You should not modify this
Number of bits in registers
Default value in
global_varsis 88 is also the maximum value since everything in RAM should fit in a byte
- bits (
- Returns:
Noneor program state ifreturn_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
- debug (
- 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)
- change (
- table_format (
str) – Printed table format
Options: https://github.com/astanin/python-tabulate#table-format
Default value in
global_varsis"simple_outline"
- table_format (
- 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 returnedSee
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
- return_state (
- non_blocking (
bool) – This is used to unit test debug mode of
run(), you likely don’t have a need for thisIf
True, thenrun()won’t block on inputinput()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 ifdebugisn’t in kwargs
- non_blocking (
- no_print (
bool) – This is used to save computation time during unit testing
If
True, thenprint_RAM()andprint_info()won’t be calledIn debug mode, “Program halted.” will still be printed
- no_print (
- bits (
int) – You should not modify this
Number of bits in registers
Default value in
global_varsis 88 is also the maximum value since everything in RAM should fit in a byte
- bits (
- Returns:
Noneor program state ifreturn_state- Returns:
dictcontaining program state (seehelpers.get_state)- Return type:
dict[str, Any]