View Javadoc

1   package com.tapina.robe.runtime.instruction;
2   
3   import com.tapina.robe.runtime.Instruction;
4   import com.tapina.robe.runtime.Condition;
5   import com.tapina.robe.runtime.Environment;
6   import com.tapina.robe.runtime.CPU;
7   
8   import java.io.Writer;
9   import java.io.IOException;
10  
11  /***
12   * Created by IntelliJ IDEA.
13   * User: gareth
14   * Date: Sep 2, 2003
15   * Time: 8:07:33 AM
16   */
17  public class MultiplyInstruction extends Instruction {
18      final int Rd;
19      final int Rs, Rm;
20      final boolean setConditionCodes;
21  
22      public MultiplyInstruction(Condition condition, int destinationRegister, int factorRegister1,
23                                 int factorRegister2, boolean setConditionCodes) {
24          super(condition);
25          this.Rd = destinationRegister;
26          this.Rs = factorRegister1;
27          this.Rm = factorRegister2;
28          this.setConditionCodes = setConditionCodes;
29      }
30  
31      protected final boolean execute(Environment environment) {
32          final CPU cpu = environment.getCpu();
33          final int[] R = cpu.R;
34  
35          if (Rd != 15) {
36              calculate(R);
37  
38              if (setConditionCodes) {
39                  Operator.setZNFlags(R[Rd], cpu);
40              }
41          }
42          return false;
43      }
44  
45      void calculate(final int[] R) {
46          R[Rd] = R[Rm] * R[Rs];
47      }
48  
49      public void dumpJavaSourceUnconditional(Writer out) throws IOException {
50          if (Rd != 15) {
51              out.write("R[" + Rd + "] = R[" + Rm + "] * R[" + Rs + "];\n");
52              if (setConditionCodes) {
53                  out.write("Operator.setZNFlags(R[" + Rd + "], cpu);\n");
54              }
55          }
56      }
57  }