public static TranslationResult extendSign(final ITranslationEnvironment environment,final long offset,final String value,final OperandSize size,final OperandSize extendedSize) throws IllegalArgumentException {
  Preconditions.checkNotNull(environment,"Error: Argument environment can't be null");
  Preconditions.checkNotNull(value,"Error: Argument value can't be null");
  Preconditions.checkNotNull(size,"Error: Argument size can't be null");
  Preconditions.checkNotNull(extendedSize,"Error: Argument extendedSize can't be null");
  Preconditions.checkArgument(size.getByteSize() < extendedSize.getByteSize(),"Error: Argument size must be smaller than argument extendedSize");
  final ArrayList<ReilInstruction> instructions=new ArrayList<ReilInstruction>();
  final String msbMask=String.valueOf(TranslationHelpers.getMsbMask(size));
  final String truncateMask=String.valueOf(TranslationHelpers.getAllBitsMask(extendedSize));
  final String toggledMsb=environment.getNextVariableString();
  final String extendedValue=environment.getNextVariableString();
  final String truncatedValue=environment.getNextVariableString();
  instructions.add(ReilHelpers.createXor(offset,size,value,size,msbMask,size,toggledMsb));
  instructions.add(ReilHelpers.createSub(offset + 1,size,toggledMsb,size,msbMask,extendedSize,extendedValue));
  instructions.add(ReilHelpers.createAnd(offset + 2,extendedSize,extendedValue,extendedSize,truncateMask,extendedSize,truncatedValue));
  return new TranslationResult(truncatedValue,extendedSize,TranslationResultType.REGISTER,null,instructions,offset);
}

public static TranslationResult extendSign ( final ITranslationEnvironment environment , final long offset , final String value , final OperandSize size , final OperandSize extendedSize ) throws IllegalArgumentException { Preconditions . checkNotNull ( environment , "Error: Argument environment can't be null" ) ; Preconditions . checkNotNull ( value , "Error: Argument value can't be null" ) ; Preconditions . checkNotNull ( size , "Error: Argument size can't be null" ) ; Preconditions . checkNotNull ( extendedSize , "Error: Argument extendedSize can't be null" ) ; Preconditions . checkArgument ( size . getByteSize ( ) < extendedSize . getByteSize ( ) , "Error: Argument size must be smaller than argument extendedSize" ) ; final ArrayList < ReilInstruction > instructions = new ArrayList < ReilInstruction > ( ) ; final String msbMask = String . valueOf ( TranslationHelpers . getMsbMask ( size ) ) ; final String truncateMask = String . valueOf ( TranslationHelpers . getAllBitsMask ( extendedSize ) ) ; final String toggledMsb = environment . getNextVariableString ( ) ; final String extendedValue = environment . getNextVariableString ( ) ; final String truncatedValue = environment . getNextVariableString ( ) ; instructions . add ( ReilHelpers . createXor ( offset , size , value , size , msbMask , size , toggledMsb ) ) ; instructions . add ( ReilHelpers . createSub ( offset + 1 , size , toggledMsb , size , msbMask , extendedSize , extendedValue ) ) ; instructions . add ( ReilHelpers . createAnd ( offset + 2 , extendedSize , extendedValue , extendedSize , truncateMask , extendedSize , truncatedValue ) ) ; return new TranslationResult ( truncatedValue , extendedSize , TranslationResultType . REGISTER , null , instructions , offset ) ; }
extends the sign of a value to the next higher data size . attention : caller must mask op down to the specified size to make this work .
