mnemonics package

Submodules

mnemonics.arithmetic module

class mnemonics.arithmetic.AddMnemonic(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Bases: _ABCBasicMnemonic

The ADD instruction in assembler performs the addition of two operands.

A mandatory rule is that the operands are equal in size; only two 16-bit numbers or two 8-bit numbers can be added to each other.

__init__(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Initialize a mnemonic.

_abc_impl = <_abc._abc_data object>
_generate_default_comment() str[source]

Generates context-sensitive default comment based on operands.

Returns:

Appropriately formatted comment string.

_validate() None[source]

Validate the mnemonic.

class mnemonics.arithmetic.DecMnemonic(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Bases: _ABCBasicMnemonic

The ASM DEC mnemonic is a decrement instruction. It decrements the register.

__init__(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Initialize a mnemonic.

_abc_impl = <_abc._abc_data object>
_generate_default_comment() str[source]

Generates context-sensitive default comment based on operands.

Returns:

Appropriately formatted comment string.

_validate() None[source]

Validate the mnemonic.

class mnemonics.arithmetic.DivMnemonic(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Bases: _ABCBasicMnemonic

The ASM DIV mnemonic is a division instruction.

It divise the source operand from the destination operand and replaces the destination with the result.

__init__(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Initialize a mnemonic.

_abc_impl = <_abc._abc_data object>
_generate_default_comment() str[source]

Generates context-sensitive default comment based on operands.

Returns:

Appropriately formatted comment string.

_validate() None[source]

Validate the mnemonic.

class mnemonics.arithmetic.IncMnemonic(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Bases: _ABCBasicMnemonic

The ASM INC mnemonic is a increment instruction. It increments the register.

__init__(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Initialize a mnemonic.

_abc_impl = <_abc._abc_data object>
_generate_default_comment() str[source]

Generates context-sensitive default comment based on operands.

Returns:

Appropriately formatted comment string.

_validate() None[source]

Validate the mnemonic.

class mnemonics.arithmetic.MulMnemonic(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Bases: _ABCBasicMnemonic

The ASM MUL mnemonic is a multiplication instruction.

It multiplicates the source operand from the destination operand and replaces the destination with the result.

__init__(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Initialize a mnemonic.

_abc_impl = <_abc._abc_data object>
_generate_default_comment() str[source]

Generates context-sensitive default comment based on operands.

Returns:

Appropriately formatted comment string.

_validate() None[source]

Validate the mnemonic.

class mnemonics.arithmetic.SubMnemonic(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Bases: _ABCBasicMnemonic

The ASM sub mnemonic is a subtraction instruction.

It subtracts the source operand from the destination operand and replaces the destination with the result.

__init__(*operands: tuple[Register | str | int], enable_comment: bool = True)[source]

Initialize a mnemonic.

_abc_impl = <_abc._abc_data object>
_generate_default_comment() str[source]

Generates context-sensitive default comment based on operands.

Returns:

Appropriately formatted comment string.

_validate() None[source]

Validate the mnemonic.

mnemonics.base module

class mnemonics.base._ABCBasicMnemonic(mnemonic_name: str, *operands: Register | str | int, enable_comment: bool = True)[source]

Bases: ABC

Base class for assembly mnemonics with flexible operand handling.

This class provides core functionality for constructing assembly instructions with variable number of operands and automatic comment generation.

mnemonic_name

Assembly instruction name (e.g., ‘mov’, ‘add’).

operands

Sequence of instruction operands.

enable_comment

Flag to control comment generation.

comment

Custom comment for the instruction.

__init__(mnemonic_name: str, *operands: Register | str | int, enable_comment: bool = True) None[source]

Initializes mnemonic with operands and comment settings.

Parameters:
  • mnemonic_name – Name of the assembly instruction.

  • *operands – Variable-length sequence of instruction operands.

  • enable_comment – Whether to generate comments in output.

_abc_impl = <_abc._abc_data object>
_format_operands() str[source]

Formats operands for instruction assembly.

Returns:

Comma-separated operand string.

_generate_default_comment() str[source]

Generates context-sensitive default comment based on operands.

Returns:

Appropriately formatted comment string.

abstractmethod _validate()[source]

Validate mnemonics operands and other fields.

_validate_operand_types() None[source]

Validates operand types against allowed types.

Raises:

TypeError – If any operand has invalid type.

property comment: str | None

Gets the current comment for the instruction.

construct(indent: str = '') str[source]

Constructs complete assembly instruction string.

Parameters:

indent – Leading indentation for the instruction.

Returns:

Formatted assembly instruction with optional comment.

class mnemonics.base._BasicMnemonic(mnemonic_name: str, *operands: Register | str | int, enable_comment: bool = True)[source]

Bases: _ABCBasicMnemonic

_abc_impl = <_abc._abc_data object>
_validate()[source]

Validate mnemonics operands and other fields.

Module contents