Let's check out how to use
AssemblyConverter. First, let's import it into our Python file:
We can now instantiate an object. The constructor's defaults are initialized as so:
output_type refers to whether a converted file should be outputted to a binary file (
"b"), a text file (
"t"), or to console (
"p"). The three of these options can be used in any sort of combination. Here are acceptable usages:
nibble refers to whether (for text file and console outputs) the 32-bit binary numbers should be split in nibbles or kept as an unbroken string. An example output for
nibble = True would be:
An example for the default
nibble = False would be:
hexMode gives the option (for text file and console outputs) to output in hexadecimal form instead of binary. By default, the outputs are in binary. Leading zeros are included to properly represent a 32-bit instruction.
With this object we can apply our most powerful function :
convert(). This function takes in a file name (with
.s extension) from the local directory and converts it to the output file of your choice, specified by the object construction. Let's convert the file
Any empty files, fully commented files, or files without
.s extension will not be accepted. The function creates a directory by truncating the extension of the file along with two subdirectories called
txt for the respective output files (for
simple.s the directory would be
simple). Output files will be stored there for usage and/or printed to console.
Here are a few functions that might be useful.
It is possible to get and set the output type of your
AssemblyConverter object. Observe:
instructionExists(instr)returns a boolean for whether