def make_masked_opcode(mnemonic, sequence, mask):
    o = OPCODES[mnemonic]
    return ((0o4000 * sequence) + (0o100 * mask) + (0o40 * o.b7) + o.op) def make_unmasked_opcode(mnemonic, sequence, a, b, c):
    o = OPCODES[mnemonic]
    return ((0o4000 * sequence) + (0o1000 * o.b23) + (0o400 * a) +
            (0o200 * b) + (0o100 * c) + o.op) def make_peripheral_opcode(mnemonic, paddr):
    o = OPCODES[mnemonic]
    return ((0o100 * paddr) + (0o40 * o.b7) + o.op) def make_print_opcode(mnemonic, sequence, a, b, c):
    o = OPCODES[mnemonic]
    return ((0o4000 * sequence) + (0o400 * a) + (0o200 * b) + (0o100 * c) +
            (0o40 * o.b7) + o.op) class BinaryAdd(instruction.Instruction):

    def __init__(self, sequence=None, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["BA"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class DecimalAdd(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["DA"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class WordAdd(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["WA"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class BinarySubtract(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["BS"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class DecimalSubtract(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["DS"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class WordDifference(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["WD"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class NotEqualAlphabetic(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["NA"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class NotEqualNumeric(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["NN"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class LessThanOrEqualAlphabetic(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["LA"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class LessThanOrEqualNumeric(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["LN"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class Transfer(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["TX"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class TransferChangeSequence(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["TS"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class HalfAdd(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["HA"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class Superimpose(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["SM"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class CheckParity(instruction.Instruction):

    def __init__(self, sequence, mask=None, a=None, b=None, c=None):
        super().__init__(opcode=OPCODES["CP"], sequence=sequence,
                         mask=mask, a=a, b=b, c=c) class BinaryMultiply(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["BM"], sequence=sequence,
                         a=a, b=b, c=c) class DecimalMultiply(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["DM"], sequence=sequence,
                         a=a, b=b, c=c) class BinaryAccumulate(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["BT"], sequence=sequence,
                         a=a, b=b, c=c) class DecimalAccumulate(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["DT"], sequence=sequence,
                         a=a, b=b, c=c) class MultipleTransfer(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["MT"], sequence=sequence,
                         a=a, b=b, c=c) class TransferNWords(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["TN"], sequence=sequence,
                         a=a, b=b, c=c) class ComputeOrthocount(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["CC"], sequence=sequence,
                         a=a, b=b, c=c) class ItemTransfer(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["IT"], sequence=sequence,
                         a=a, b=b, c=c) class ExtendedBinaryAdd(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["EBA"], sequence=sequence,
                         a=a, b=b, c=c) class ExtendedBinarySubtract(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["EBS"], sequence=sequence,
                         a=a, b=b, c=c) class RecordTransfer(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["RT"], sequence=sequence,
                         a=a, b=b, c=c) class ControlProgram(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["MPC"], sequence=sequence,
                         a=a, b=b, c=c) class Proceed(instruction.GeneralUnmasked):

    def __init__(self):
        super().__init__(opcode=OPCODES["PR"], sequence=0, a=0, b=0, c=0) class ShiftWordAndSubstitute(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["SWS"], sequence=sequence,
                         a=a, b=b, c=c) class ShiftPreservingSignAndSubstitute(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["SPS"], sequence=sequence,
                         a=a, b=b, c=c) class ShiftWordAndExtract(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["SWE"], sequence=sequence,
                         a=a, b=b, c=c) class ShiftPreservingSignAndExtract(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["SPE"], sequence=sequence,
                         a=a, b=b, c=c) class ShiftAndSelect(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["SSL"], sequence=sequence,
                         a=a, b=b, c=c) class Substitute(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["SS"], sequence=sequence,
                         a=a, b=b, c=c) class Extract(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["EX"], sequence=sequence,
                         a=a, b=b, c=c) class ReadForward(instruction.Peripheral):

    def __init__(self, paddr):
        super().__init__(opcode=OPCODES["RF"], paddr=paddr) class ReadBackward(instruction.Peripheral):

    def __init__(self, paddr):
        super().__init__(opcode=OPCODES["RB"], paddr=paddr) class WriteForward(instruction.Peripheral):

    def __init__(self, paddr):
        super().__init__(opcode=OPCODES["WF"], paddr=paddr) class Rewind(instruction.Peripheral):

    def __init__(self, paddr):
        super().__init__(opcode=OPCODES["RW"], paddr=paddr) class PrintAlphabetic(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["PRA"], sequence=sequence,
                         a=a, b=b, c=c) class PrintDecimal(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["PRD"], sequence=sequence,
                         a=a, b=b, c=c) class PrintOctal(instruction.GeneralUnmasked):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["PRO"], sequence=sequence,
                         a=a, b=b, c=c) class Simulator(instruction.Simulator):

    def __init__(self, sequence):
        super().__init__(opcode=OPCODES["S"], sequence=sequence) class FloatingBinaryAdd(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FBA"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingDecimalAdd(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FDA"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingBinarySubtract(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FBS"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingDecimalSubtract(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FDS"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingBinaryDivide(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FBD"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingDecimalDivide(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FDD"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingBinaryAddUnnormalized(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FBAU"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingDecimalAddUnnormalized(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FDAU"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingBinarySubtractUnnormalized(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FBSU"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingDecimalSubtractUnnormalized(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FDSU"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingBinaryMultiply(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FBM"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingDecimalMultiply(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FDM"], sequence=sequence,
                         a=a, b=b, c=c) class MultipleUnload(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["ULD"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingBinaryAddExtendedPrecision(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FBAE"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingBinarySubtractExtendedPrecision(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FBSE"], sequence=sequence,
                         a=a, b=b, c=c) class FixedBinaryDivide(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["BD"], sequence=sequence,
                         a=a, b=b, c=c) class FixedDecimalDivide(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["DD"], sequence=sequence,
                         a=a, b=b, c=c) class FixedToFloatingNormalize(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FFN"], sequence=sequence,
                         a=a, b=b, c=c) class Conversion(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FCON"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingLessThanNormalized(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FLN"], sequence=sequence,
                         a=a, b=b, c=c) class FloatingNotEqualNormalized(instruction.Scientific):

    def __init__(self, sequence, a, b, c):
        super().__init__(opcode=OPCODES["FNN"], sequence=sequence,
                         a=a, b=b, c=c) class AlphanumericConstant(instruction.Constant):

    def __init__(self, data):
        super().__init__(mnemonic="ALF", data=data) class DecimalConstant(instruction.Constant):

    def __init__(self, data):
        super().__init__(mnemonic="DEC", data=data) class ExtendedBinaryConstant(instruction.Constant):

    def __init__(self, data):
        super().__init__(mnemonic="EBC", data=data) class FloatingBinaryConstant(instruction.Constant):

    def __init__(self, data):
        super().__init__(mnemonic="FLBIN", data=data) class FloatingDecimalConstant(instruction.Constant):

    def __init__(self, data):
        super().__init__(mnemonic="FLDEC", data=data) class FixedBinaryConstant(instruction.Constant):

    def __init__(self, data):
        super().__init__(mnemonic="FXBIN", data=data) class OctalConstant(instruction.Constant):

    def __init__(self, data):
        super().__init__(mnemonic="OCT", data=data) OPCODES = {

    # Table format:
    #
    #   Mnemonic:  Opcode(Mnemonic, Class,
    #                     Unmasked bits 2-3, Masked bit 7, bits 8-12,
    #                     "maskable" / "peripheral" / "print" / "simulator")

    # General, masked or unmasked.
    "BA":   Opcode("BA", "BinaryAdd",
                   0b10, 0b1, 0o11, "maskable"),

    "DA":   Opcode("DA", "DecimalAdd",
                   0b10, 0b1, 0o01, "maskable"),

    "WA":   Opcode("WA", "WordAdd",
                   0b10, 0b1, 0o15, "maskable"),

    "BS":   Opcode("BS", "BinarySubtract",
                   0b10, 0b1, 0o31, "maskable"),

    "DS":   Opcode("DS", "DecimalSubtract",
                   0b10, 0b1, 0o21, "maskable"),

    "WD":   Opcode("WD", "WordDifference",
                   0b10, 0b1, 0o35, "maskable"),

    "NA":   Opcode("NA", "NotEqualAlphabetic",
                   0b10, 0b1, 0o14, "maskable"),

    "NN":   Opcode("NN", "NotEqualNumeric",
                   0b10, 0b1, 0o10, "maskable"),

    "LA":   Opcode("LA", "LessThanOrEqualAlphabetic",
                   0b10, 0b1, 0o34, "maskable"),

    "LN":   Opcode("LN", "LessThanOrEqualNumeric",
                   0b10, 0b1, 0o30, "maskable"),

    "TX":   Opcode("TX", "Transfer",
                   0b10, 0b1, 0o20, "maskable"),

    "TS":   Opcode("TS", "TransferAndChangeSequence",
                   0b10, 0b1, 0o04, "maskable"),

    "HA":   Opcode("HA", "HalfAdd",
                   0b10, 0b1, 0o25, "maskable"),

    "SM":   Opcode("SM", "Superimpose",
                   0b10, 0b1, 0o05, "maskable"),

    "CP":   Opcode("CP", "CheckParity",
                   0b10, 0b1, 0o24, "maskable"),

    # General, unmasked.
    "BM":   Opcode("BM", "BinaryMultiply",
                   0b00, 0b0, 0o13),

    "DM":   Opcode("DM", "DecimalMultiply",
                   0b00, 0b0, 0o03),

    "BT":   Opcode("BT", "BinaryAccumulate",
                   0b10, 0b0, 0o13),

    "DT":   Opcode("DT", "DecimalAccumulate",
                   0b10, 0b0, 0o03),

    "MT":   Opcode("MT", "MultipleTransfer",
                   0b00, 0b0, 0o20),

    "TN":   Opcode("TN", "TransferNWords",
                   0b01, 0b0, 0o20),

    "CC":   Opcode("CC", "ComputeOrthocount",
                   0b01, 0b0, 0o10),

    "IT":   Opcode("IT", "ItemTransfer",
                   0b01, 0b0, 0o30),

    "EBA":  Opcode("EBA", "ExtendedBinaryAdd",
                   0b11, 0b0, 0o13),

    "EBS":  Opcode("EBS", "ExtendedBinarySubtract",
                   0b11, 0b0, 0o33),

    "RT":   Opcode("RT", "RecordTransfer",
                   0b11, 0b0, 0o30),

    "MPC":  Opcode("MPC", "ControlProgram",
                   0b10, 0b0, 0o00),

    "PR":   Opcode("PR", "Proceed",
                   0b00, 0b0, 0o00),

    # Inherent mask.
    "SWS":  Opcode("SWS", "ShiftWordAndSubstitute",
                   0b10, 0b0, 0o06),

    "SPS":  Opcode("SPS", "ShiftPreservingSignAndSubstitute",
                   0b10, 0b0, 0o02),

    "SWE":  Opcode("SWE", "ShiftWordAndExtract",
                   0b10, 0b0, 0o16),

    "SPE":  Opcode("SPE", "ShiftPreservingSignAndExtract",
                   0b10, 0b0, 0o12),

    "SSL":  Opcode("SSL", "ShiftAndSelect",
                   0b10, 0b0, 0o26),

    "SS":   Opcode("SS", "Substitute",
                   0b00, 0b0, 0o06),

    "EX":   Opcode("EX", "Extract",
                   0b00, 0b0, 0o16),

    # Peripheral and print.
    "RF":   Opcode("RF", "ReadForward",
                   None, 0b1, 0o32, "peripheral"),

    "RB":   Opcode("RB", "ReadBackward",
                   None, 0b1, 0o12, "peripheral"),

    "WF":   Opcode("WF", "WriteForward",
                   None, 0b1, 0o16, "peripheral"),

    "RW":   Opcode("RW", "Rewind",
                   None, 0b1, 0o02, "peripheral"),

    "PRA":  Opcode("PRA", "PrintAlphabetic",
                   None, 0b1, 0o06, "print"),

    "PRD":  Opcode("PRD", "PrintDecimal",
                   None, 0b1, 0o06, "print"),

    "PRO":  Opcode("PRO", "PrintOctal",
                   None, 0b1, 0o06, "print"),

    # Simulator.
    "S":    Opcode("S", "Simulator",
                   None, None, 0o07, "simulator"),

    # Scientific.
    "FBA":  Opcode("FBA", "FloatingBinaryAdd",
                   0b01, 0b0, 0o01),

    "FDA":  Opcode("FDA", "FloatingDecimalAdd",
                   0b01, 0b0, 0o21),

    "FBS":  Opcode("FBS", "FloatingBinarySubtract",
                   0b01, 0b0, 0o11),

    "FDS":  Opcode("FDS", "FloatingDecimalSubtract",
                   0b01, 0b0, 0o31),

    "FBD":  Opcode("FBD", "FloatingBinaryDivide",
                   0b01, 0b0, 0o05),

    "FDD":  Opcode("FDD", "FloatingDecimalDivide",
                   0b01, 0b0, 0o25),

    "FBAU": Opcode("FBAU", "FloatingBinaryAddUnnormalized",
                   0b11, 0b0, 0o01),

    "FDAU": Opcode("FDAU", "FloatingDecimalAddUnnormalized",
                   0b11, 0b0, 0o21),

    "FBSU": Opcode("FBSU", "FloatingBinarySubtractUnnormalized",
                   0b11, 0b0, 0o11),

    "FDSU": Opcode("FDSU", "FloatingDecimalSubtractUnnormalized",
                   0b11, 0b0, 0o31),

    "FBM":  Opcode("FBM", "FloatingBinaryMultiply",
                   0b11, 0b0, 0o05),

    "FDM":  Opcode("FDM", "FloatingDecimalMultiply",
                   0b11, 0b0, 0o25),

    "ULD":  Opcode("ULD", "MultipleUnload",
                   0b11, 0b0, 0o15),

    "FBAE": Opcode("FBAE", "FloatingBinaryAddExtendedPrecision",
                   0b00, 0b0, 0o01),

    "FBSE": Opcode("FBSE", "FloatingBinarySubtractExtendedPrecision",
                   0b00, 0b0, 0o11),

    "BD":   Opcode("BD", "FixedBinaryDivide",
                   0b00, 0b0, 0o05),

    "DD":   Opcode("DD", "FixedDecimalDivide",
                   0b00, 0b0, 0o25),

    "FFN":  Opcode("FFN", "FixedToFloatingNormalize",
                   0b00, 0b0, 0o15),

    "FCON": Opcode("FCON", "Conversion",
                   0b00, 0b0, 0o35),

    "FLN":  Opcode("FLN", "FloatingLessThanNormalized",
                   0b00, 0b0, 0o30),

    "FNN":  Opcode("FNN", "FloatingNotEqualNormalized",
                   0b10, 0b0, 0o14)
}
from collections import namedtuple
from .instructions import make_masked_opcode, make_unmasked_opcode, \
    make_peripheral_opcode, make_print_opcode, \
    BinaryAdd, DecimalAdd, WordAdd, \
    BinarySubtract, DecimalSubtract, WordDifference, \
    NotEqualAlphabetic, NotEqualNumeric, \
    LessThanOrEqualAlphabetic, LessThanOrEqualNumeric, \
    Transfer, TransferChangeSequence, \
    HalfAdd, Superimpose, CheckParity, \
    BinaryMultiply, DecimalMultiply, \
    BinaryAccumulate, DecimalAccumulate, \
    MultipleTransfer, TransferNWords, \
    ComputeOrthocount, ItemTransfer, \
    ExtendedBinaryAdd, ExtendedBinarySubtract, \
    RecordTransfer, ControlProgram, Proceed, \
    ShiftWordAndSubstitute, ShiftPreservingSignAndSubstitute, \
    ShiftWordAndExtract, ShiftPreservingSignAndExtract, ShiftAndSelect, \
    Substitute, Extract, \
    ReadForward, ReadBackward, WriteForward, Rewind, \
    PrintAlphabetic, PrintDecimal, PrintOctal, Simulator, \
    FloatingBinaryAdd, FloatingDecimalAdd, \
    FloatingBinarySubtract, FloatingDecimalSubtract, \
    FloatingBinaryDivide, FloatingDecimalDivide, \
    FloatingBinaryAddUnnormalized, FloatingDecimalAddUnnormalized, \
    FloatingBinarySubtractUnnormalized, FloatingDecimalSubtractUnnormalized, \
    FloatingBinaryMultiply, FloatingDecimalMultiply, MultipleUnload, \
    FloatingBinaryAddExtendedPrecision, \
    FloatingBinarySubtractExtendedPrecision, \
    FixedBinaryDivide, FixedDecimalDivide, FixedToFloatingNormalize, \
    Conversion, FloatingLessThanNormalized, FloatingNotEqualNormalized, \
    AlphanumericConstant, DecimalConstant, ExtendedBinaryConstant, \
    FloatingBinaryConstant, FloatingDecimalConstant, FixedBinaryConstant, \
    OctalConstant, \
    OPCODES
    c = CheckParity
    testdata = []
    for i in range(2):
        for j in range(2):
            for k in range(2):
                for l in range(2):
                    testdata.append([c, UnmaskedTestData(i, j, k, l),
                                     make_unmasked_opcode("CP", i, j, k, l)])
    run_tests("TEST: CP (unmasked): args range", testdata)


# ######## BM ########

def test_BM_simple():
    c = BinaryMultiply
    testdata = [[c, UnmaskedTestData(0, 0, 0, 0), 0o13]]
    run_tests("TEST: BM simple", testdata)


def test_BM_invalid_args():
    c = BinaryMultiply
    testdata = [
        [c, UnmaskedTestData(2, 0, 0, 0), 0],
        [c, UnmaskedTestData(0, 2, 0, 0), 0],
        [c, UnmaskedTestData(0, 1, 2, 3), 0]
    ]
    run_exception_tests("TEST: BM invalid args", testdata)


def test_BM_args_range():
    c = BinaryMultiply
    testdata = []
    for i in range(2):
        for j in range(2):
            for k in range(2):
                for l in range(2):
                    testdata.append([c, UnmaskedTestData(i, j, k, l),
                                     make_unmasked_opcode("BM", i, j, k, l)])
    run_tests("TEST: BM args range", testdata)


# ######## DM ########

def test_DM_simple():
    c = DecimalMultiply
    testdata = [[c, UnmaskedTestData(0, 0, 0, 0), 0o03]]
    run_tests("TEST: DM simple", testdata)


def test_DM_invalid_args():
    c = DecimalMultiply
    testdata = [
        [c, UnmaskedTestData(2, 0, 0, 0), 0],
        [c, UnmaskedTestData(0, 2, 0, 0), 0],
        [c, UnmaskedTestData(0, 1, 2, 3), 0]
    ]
    run_exception_tests("TEST: DM invalid args", testdata)


def test_DM_args_range():
    c = DecimalMultiply
    testdata = []
    for i in range(2):
        for j in range(2):
            for k in range(2):
                for l in range(2):
                    testdata.append([c, UnmaskedTestData(i, j, k, l),
                                     make_unmasked_opcode("DM", i, j, k, l)])
    run_tests("TEST: DM args range", testdata)


# ######## BT ########

def test_BT_simple():
    c = BinaryAccumulate
    testdata = [[c, UnmaskedTestData(0, 0, 0, 0), 0o2013]]
    run_tests("TEST: BT simple", testdata)


def test_BT_invalid_args():
    c = BinaryAccumulate
    testdata = [
        [c, UnmaskedTestData(2, 0, 0, 0), 0],
        [c, UnmaskedTestData(0, 2, 0, 0), 0],
        [c, UnmaskedTestData(0, 1, 2, 3), 0]
    ]
    run_exception_tests("TEST: BT invalid args", testdata)


def test_BT_args_range():
    c = BinaryAccumulate
    testdata = []
    for i in range(2):
        for j in range(2):
            for k in range(2):
                for l in range(2):
                    testdata.append([c, UnmaskedTestData(i, j, k, l),
                                     make_unmasked_opcode("BT", i, j, k, l)])
    run_tests("TEST: BT args range", testdata)


# ######## DT ########

def test_DT_simple():
    c = DecimalAccumulate
    testdata = [[c, UnmaskedTestData(0, 0, 0, 0), 0o2003]]
    run_tests("TEST: DT simple", testdata)


def test_DT_invalid_args():
    c = DecimalAccumulate
    testdata = [
        [c, UnmaskedTestData(2, 0, 0, 0), 0],
        [c, UnmaskedTestData(0, 2, 0, 0), 0],
        [c, UnmaskedTestData(0, 1, 2, 3), 0]
    ]
    run_exception_tests("TEST: DT invalid args", testdata)


def test_DT_args_range():

    c = DecimalAccumulate