View Javadoc

1   package com.tapina.robe.runtime.instruction;
2   
3   import com.tapina.robe.runtime.CPU;
4   
5   import java.io.Writer;
6   import java.io.IOException;
7   
8   /***
9    * Created by IntelliJ IDEA.
10   * User: gareth
11   * Date: Sep 2, 2003
12   * Time: 4:53:58 PM
13   */
14  public final class PostIndexedAddressSource extends IndexedAddressSource {
15      public PostIndexedAddressSource(int baseRegister, Operand offset) {
16          super(baseRegister, offset);
17      }
18  
19      public final int getTransferAddress(CPU cpu) {
20          final int address = baseRegister == 15? cpu.getPC() : cpu.R[baseRegister];
21  
22          cpu.R[baseRegister] += offset.getValue(cpu);
23          return address;
24      }
25  
26      public void dumpJavaSource(String varName, Writer out) throws IOException {
27          out.write("final int " + varName + " = ");
28          if (baseRegister == 15) {
29              out.write("cpu.getPc();\n");
30          } else {
31              out.write("R[" + baseRegister + "];\n");
32          }
33          offset.dumpJavaSource("offset", out);
34          out.write("R[" + baseRegister + "] += offset;\n");
35      }
36  }