public static List<ReilInstruction> translate( final StandardEnvironment environment, final Instruction instruction) { final List<ReilInstruction> instructions = new FilledList<ReilInstruction>(); final int baseOffset = instruction.getAddress() * 0x100; int offset = baseOffset; final TranslationResult operandResult = OperandTranslator.translate( environment, offset, instruction.getOperand(), true, instruction); instructions.addAll(operandResult.getInstructions()); offset = baseOffset + instructions.size(); final String subResult = environment.getNextVariableString(); final String truncatedResult = environment.getNextVariableString(); instructions.add( ReilHelpers.createSub( offset++, OperandSize.BYTE, operandResult.getResultRegister(), OperandSize.BYTE, "1", OperandSize.WORD, subResult, instruction)); instructions.add( ReilHelpers.createAnd( offset++, OperandSize.WORD, subResult, OperandSize.BYTE, "255", OperandSize.BYTE, truncatedResult, instruction)); instructions.add( ReilHelpers.createStm( offset++, OperandSize.BYTE, truncatedResult, OperandSize.WORD, operandResult.getMemoryAddress(), instruction)); instructions.addAll( FlagTranslator.translateZ( environment, offset + instructions.size(), truncatedResult, instruction)); instructions.addAll( FlagTranslator.translateN( environment, offset + instructions.size(), truncatedResult, instruction)); return instructions; }
public static List<ReilInstruction> translate( final StandardEnvironment environment, final Instruction instruction) { final List<ReilInstruction> instructions = new FilledList<ReilInstruction>(); final int baseOffset = instruction.getAddress() * 0x100; int offset = baseOffset; String source; String target; if (instruction.getOperand() == null) { source = "A"; target = "A"; } else { final TranslationResult operandResult = OperandTranslator.translate( environment, offset, instruction.getOperand(), true, instruction); instructions.addAll(operandResult.getInstructions()); offset = baseOffset + instructions.size(); source = operandResult.getResultRegister(); target = operandResult.getMemoryAddress(); } final String shiftResult = environment.getNextVariableString(); final String truncatedResult = instruction.getOperand() == null ? "A" : environment.getNextVariableString(); instructions.add( ReilHelpers.createBsh( offset++, OperandSize.BYTE, source, OperandSize.BYTE, "1", OperandSize.WORD, shiftResult, instruction)); instructions.add( ReilHelpers.createAnd( offset++, OperandSize.WORD, shiftResult, OperandSize.BYTE, "255", OperandSize.BYTE, truncatedResult, instruction)); if (instruction.getOperand() != null) { instructions.add( ReilHelpers.createStm( offset++, OperandSize.BYTE, truncatedResult, OperandSize.WORD, target, instruction)); } instructions.addAll( FlagTranslator.translateZ( environment, baseOffset + instructions.size(), truncatedResult, instruction)); instructions.addAll( FlagTranslator.translateN( environment, baseOffset + instructions.size(), truncatedResult, instruction)); instructions.addAll( FlagTranslator.translateC( environment, baseOffset + instructions.size(), shiftResult, instruction)); return instructions; }