Assembler { public static byte processDirectInstructionWithConstantOperand(Instruction instruction) { if ("opr".equals(instruction.opcode.opcode)) { throw new IllegalArgumentException("Found unexpected 'opr' instructionPattern"); } if (instruction.constantOperand == null) { throw new IllegalArgumentException("Operand cannot be null"); } if (0x0 <= instruction.constantOperand && instruction.constantOperand <= 0xF) { return (byte) ((instruction.opcode.encodesTo << 4) | instruction.constantOperand & 0xF); } else { throw new IllegalArgumentException("Operand for direct instructionPattern must be between in range 0x0 to 0xF"); } } 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 testProcessDirectInstructionWithConstantOperand() { assertEquals((byte) 0x4A, Assembler.processDirectInstructionWithConstantOperand(new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("ldc"), 10L, null, null, null, 1))); }