Example #1
0
def _(operand):
    offset, base = single(operand.items())
    if not isinstance(offset, (Register, Integral)):
        raise TypeError("Expected integer offset. Got {}".format(offset))
    if not isinstance(base, (Register, AutoIncrementedRegister)):
        raise TypeError("{} is not a base".format(base))
    return Indexed(base=base, offset=offset)
Example #2
0
def _(operand):
    try:
        byte = single(operand)
    except ValueError as ve:
        raise ValueError(
            "Immediate8 string operand must contain an single ASCII character. Got {} in {!r}"
            .format(len(operand), operand)) from ve

    return Immediate(byte)
Example #3
0
def _(statement, asm):
    operand = statement.operand
    opcodes = OPCODES[statement.mnemonic]
    opcode_key = single(operand.codes & opcodes.keys())
    opcode = opcodes[opcode_key]
    asm._opcode_bytes = (opcode, ) if opcode <= 0xFF else (hi(opcode),
                                                           lo(opcode))
    operand_bytes = assemble_operand(operand, opcode_key, asm, statement)
    asm._extend(asm._opcode_bytes + operand_bytes)
Example #4
0
def _(operand):
    item = single(operand)
    if isinstance(item, Label):
        return ExtendedIndirect(item)
    elif isinstance(item, Integral):
        if item < 0:
            raise ValueError("Direct address {} is negative.".format(operand))
        if item <= 0xFFFF:
            return ExtendedIndirect(item)
        raise ValueError(
            "Indirect address 0x{:X} out of range 0x0000-0xFFFF".format(item))
    else:
        raise TypeError(
            "Expected integer address or label. Got {}".format(item))
Example #5
0
def _(statement, asm):
    operand = statement.operand

    operating_addressing_modes = set(operand.codes)

    opcodes = OPCODES[statement.mnemonic.key]
    opcode_key = single(operating_addressing_modes & opcodes.keys())
    opcode_bytes = bytes.fromhex(opcodes[opcode_key])
    # TODO: Dispatch this back to a method on the instruction
    #       Maybe assemble_with_operand instead of assembling
    #       the opcode separately here
    operand_bytes = statement.assemble_operand(operand, opcode_key, asm,
                                               opcode_bytes)
    #operand_bytes = assemble_operand(operand, opcode_key, asm, statement)
    asm._extend(opcode_bytes + operand_bytes)
Example #6
0
def _(operand):
    item = single(operand)
    return parse_indirect_operand(item)