Assembler { public static List<Byte> processIndirectInstruction(Instruction instruction) { List<Byte> result = new ArrayList<>(); if (instruction.opcode.encodesTo > 0xFF) { throw new IllegalArgumentException("Indirect instructions >0xFF are not yet supported."); } if (instruction.opcode.encodesTo > 0xF) { result.add((byte) ((opcodes.get("pfix").encodesTo << 4) | (instruction.opcode.encodesTo >>> 4))); } result.add((byte) ((opcodes.get("opr").encodesTo << 4) | (instruction.opcode.encodesTo & 0xF))); return result; } private  Assembler(); @Nullable static AssemblerConfig loadConfig(@Nullable Reader configReader); static List<String> assemble(@Nonnull String input, @Nullable AssemblerConfig config, @Nonnull PrintStream logger, boolean insertIOConfiguration); @Nonnull static List<Instruction> parseAssembly(@Nonnull String input); static List<Instruction> insertIOConfiguration(List<Instruction> instructions, AssemblerConfig config); static List<Instruction> processDollarLabelOperands(List<Instruction> instructions); static List<Instruction> processChanDirectives(List<Instruction> instructions, AssemblerConfig config); static List<Instruction> processDataDirectives(List<Instruction> instructions); static Assembly makeLabelMap(List<Instruction> instructions); static Map<String, Long> getConfigLabels(@Nonnull AssemblerConfig config); static Assembly patchLabels(Assembly assembly); static List<Byte> processIndirectInstruction(Instruction instruction); static List<Byte> processDirectInstructionWithLabelOperand(Instruction instruction, Map<String, Long> labelMap); static byte processDirectInstructionWithConstantOperand(Instruction instruction); static List<Instruction> prefix(Instruction instruction); static ParseTree parseExpression(String expression, Function<AssemblerExpressionParser, ParseTree> startRule); final static long maxInt; final static long minInt; final static Pattern inputComment; final static Pattern instructionPattern; final static Pattern directivePattern; final static Pattern dollarPattern; static Map<String, Opcode> opcodes; }
@Test public void testProcessIndirectInstructionSingleByte() { List<Byte> result = Assembler.processIndirectInstruction(new Instruction(InstructionType.INSTRUCTION, "alabel", Assembler.opcodes.get("add"), null, null, "a comment", null, 5)); assertEquals(new Byte((byte) 0xF5), result.get(0)); assertEquals(1, result.size()); }
@Test public void testProcessIndirectInstructionDoubleByte() { List<Byte> result = Assembler.processIndirectInstruction(new Instruction(InstructionType.INSTRUCTION, "alabel", Assembler.opcodes.get("ldpi"), null, null, "a comment", null, 5)); assertEquals(new Byte((byte) 0x21), result.get(0)); assertEquals(new Byte((byte) 0xFB), result.get(1)); assertEquals(2, result.size()); }