MultiplyByConstantCodeGenerator { public Decomposition generate (InstructionList il, int nFactor, boolean bGenerateTemporaryMove) { Decomposition d = null; int nAbsFactor = Math.abs (nFactor); if (nAbsFactor == 1) ; else { d = decompose (nFactor); if (d != null) { if (bGenerateTemporaryMove && d.needsTempRegister ()) il.addInstruction (new Instruction ("mov", m_reg1, m_reg2)); d.generate (il); } else { il.addInstruction (new Instruction ("imul", new IOperand.Immediate (nFactor), m_reg1)); } } if (nFactor < 0) il.addInstruction (new Instruction ("neg", m_reg1)); return d; } MultiplyByConstantCodeGenerator(IOperand.IRegisterOperand reg1, IOperand reg2);  MultiplyByConstantCodeGenerator(IOperand.IRegisterOperand reg); Decomposition generate(InstructionList il, int nFactor, boolean bGenerateTemporaryMove);  }
@Test public void testGenerate () { for (int i = 4; i < 1000; i++) { InstructionList il = new InstructionList (); m_cg1.generate (il, i, true); verifyComputation (il, i); System.out.println (i + " (allow temp reg):"); System.out.println (il.toString ()); / } }