예제 #1
0
def writeAndRead1Instruction(instruction, pointers, fo, opcode,
                             assembly_failed):
    top_byte = opcode
    if len(instruction) < 4:
        if len(instruction) < 3:
            CustomError.ERR_missingArgument(instruction[-1], '1')
            return False
        CustomError.ERR_missingArgument(instruction[-1], '2')
        return False
    if instruction[1][0] != 'r':
        CustomError.ERR_invalidArgumentType(instruction[-1], '1',
                                            "register reference")
        return False
    elif instruction[2][0] != 'r':
        CustomError.ERR_invalidArgumentType(instruction[-1], '2',
                                            "register reference")
        return False
    topmid_byte_top_nibble = registers.get(instruction[1], None)
    if topmid_byte_top_nibble == None:
        CustomError.ERR_invalidValue(instruction[-1], '1')
        return False
    botmid_byte_top_nibble = registers.get(instruction[2], None)
    if botmid_byte_top_nibble == None:
        CustomError.ERR_invalidValue(instruction[-1], '2')
        return False
    if not assembly_failed:
        fo.write("{}{}{} {}{}".format(top_byte, topmid_byte_top_nibble, '0',
                                      botmid_byte_top_nibble, "000"))
    return True
예제 #2
0
def instr_Jmp(instruction, pointers, fo, assembly_failed):
    if len(instruction) < 4:
        if len(instruction) < 3:
            CustomError.ERR_missingArgument(instruction[-1], '1')
            return False
        CustomError.ERR_missingArgument(instruction[-1], '2')
        return False
    topmid_byte_bottom_nibble = jump_flags.get(instruction[1], None)
    if topmid_byte_bottom_nibble == None:
        CustomError.ERR_invalidArgument(instruction[-1], '1')
        return False
    if instruction[2][0] != '&':
        CustomError.ERR_invalidArgumentType(instruction[-1], '2',
                                            "label reference")
        return False
    temp = pointers.get(instruction[2], None)
    if temp == None:
        CustomError.ERR_labelMissing(instruction[-1])
        return False
    low_bytes = int(temp) * 2
    if low_bytes > 65535:
        CustomError.ERR_outOfBounds(instruction[-1])
        return False
    if not assembly_failed:
        fo.write("{}{} {}".format("0d0", topmid_byte_bottom_nibble,
                                  "%.4x" % (low_bytes)))
    return True
예제 #3
0
def instr_Mov(instruction, pointers, fo, assembly_failed):
    if len(instruction) < 4:
        if len(instruction) < 3:
            CustomError.ERR_missingArgument(instruction[-1], '1')
            return False
        CustomError.ERR_missingArgument(instruction[-1], '2')
        return False
    if instruction[1][0] != 'r':
        CustomError.ERR_invalidArgumentType(instruction[-1], '1',
                                            "register reference")
        return False
    topmid_byte_top_nibble = registers.get(instruction[1], None)
    if topmid_byte_top_nibble == None:
        CustomError.ERR_invalidValue(instruction[-1], '1')
        return False
    if instruction[2][0] == 'r':
        topmid_bottom_nibble = registers.get(instruction[2], None)
        if topmid_bottom_nibble == None:
            CustomError.ERR_invalidArgumentType(instruction[-1], '1',
                                                "register reference")
            return False
        if not assembly_failed:
            fo.write("{}{}{} {}".format("00", topmid_byte_top_nibble,
                                        topmid_byte_bottom_nibble, "0000"))
        return True
    elif instruction[2][0] == 'd':
        if -32768 > int(instruction[2][1:]) > 32767:
            CustomError.ERR_invalidValue(instruction[-1], '2')
            return False
        else:
            if not assembly_failed:
                fo.write("{}{}{} {}".format(
                    "00", topmid_byte_top_nibble, '0',
                    "%4.4x" % (int(instruction[2][1:]))))
            return True
    elif len(instruction[2]) == 5 and instruction[2][0] == 'h':
        for c in instruction[2][1:]:
            if '0' <= c <= '9' or 'a' <= c <= 'f':
                continue
            else:
                CustomError.ERR_invalidValue(instruction[-1], '2')
                return False
        if not assembly_failed:
            fo.write("{}{}{} {}".format("00", topmid_byte_top_nibble, '0',
                                        instruction[2][1:]))
        return True
    else:
        CustomError.ERR_invalidArgumentType(
            instruction[-1], '2',
            "d (decimal), h (hexadecimal) or r (register reference)")
        return False
예제 #4
0
def instr_Int(instruction, pointers, fo, assembly_failed):
    if len(instruction) < 3:
        CustomError.ERR_missingArgument(instruction[-1], '1')
        return False
    if instruction[1][0] == 'd':
        temp = int(instruction[1][1:])
        if 0 > temp > 255:
            CustomError.ERR_invalidValue(instruction[-1], '1')
            return False
        else:
            if not assembly_failed:
                fo.write("{}{}{}".format("14", "0e f0", "%2.2x" % temp))
            return True
    elif len(instruction[1]) == 3 and instruction[1][0] == 'h':
        for c in instruction[1][1:]:
            if '0' <= c <= '9' or 'a' <= c <= 'f':
                continue
            else:
                CustomError.ERR_invalidValue(instruction[-1], '1')
                return False
        if not assembly_failed:
            fo.write("{}{}{}".format("14", "0e f0", instruction[1][1:]))
        return True
    else:
        CustomError.ERR_invalidArgumentType(instruction[-1], '2',
                                            "d (decimal), h (hexadecimal)")
        return False
예제 #5
0
def writeFieldWithStackInstruction(instruction, pointers, fo, opcode,
                                   assembly_failed):
    if len(instruction) < 3:
        CustomError.ERR_missingArgument(instruction[-1], '1')
        return False
    if instruction[1][0] != 'r':
        CustomError.ERR_invalidArgumentType(instruction[-1], '1',
                                            "register reference")
        return False
    topmid_byte_top_nibble = registers.get(instruction[1], None)
    if topmid_byte_top_nibble == None:
        CustomError.ERR_invalidValue(instruction[-1], '1')
        return False
    if not assembly_failed:
        fo.write("{}{}{}".format(opcode, topmid_byte_top_nibble, "e f000"))
    return True
예제 #6
0
def instr_Call(instruction, pointers, fo, assembly_failed):
    if len(instruction) < 3:
        CustomError.ERR_missingArgument(instruction[-1], '1')
        return False
    if instruction[1][0] != '&':
        CustomError.ERR_invalidArgumentType(instruction[-1], '1',
                                            "label reference")
        return False
    temp = pointers.get(instruction[1], None)
    if temp == None:
        CustomError.ERR_labelMissing(instruction[-1])
        return False
    low_bytes = int(temp) * 2
    if low_bytes > 65535:
        CustomError.ERR_outOfBounds(instruction[-1])
        return False
    if not assembly_failed:
        fo.write("{} {}".format("0efe", "%.4x" % (low_bytes)))
    return True