コード例 #1
0
 @Override
 public Instruction translate(String instructionBinary) {
   Instruction instruction = new Instruction();
   instruction.setHint(substringAndCast(instructionBinary, 6, 11, String.class));
   instruction.setRt(
       new Register(
           InstructionUtil.binaryToDecimal(
               substringAndCast(instructionBinary, 16, 21, String.class))));
   instruction.setRd(
       new Register(
           InstructionUtil.binaryToDecimal(
               substringAndCast(instructionBinary, 11, 16, String.class))));
   instruction.setRs(
       new Register(
           InstructionUtil.binaryToDecimal(
               substringAndCast(instructionBinary, 21, 26, String.class))));
   instruction.setOpcode(substringAndCast(instructionBinary, 26, 32, String.class));
   instruction.setStringRepresentation(
       "ADD R"
           + instruction.getRd().getId()
           + ", R"
           + instruction.getRs().getId()
           + ", R"
           + instruction.getRt().getId());
   instruction.setOperator(Operator.ADD);
   return instruction;
 }
コード例 #2
0
 private static <T> T substringAndCast(String str, int f, int s, Class<T> clazz) {
   return clazz.cast(
       new StringBuilder(InstructionUtil.substringAndCast(str, f, s, clazz).toString())
           .reverse()
           .toString());
 }