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:52:51 PM 13 */ 14 public class PreIndexedAddressSource extends IndexedAddressSource { 15 public PreIndexedAddressSource(int baseRegister, Operand offset) { 16 super(baseRegister, offset); 17 } 18 19 public int getTransferAddress(CPU cpu) { 20 return (baseRegister == 15? cpu.getPC() : cpu.R[baseRegister]) + offset.getValue(cpu); 21 } 22 23 public void dumpJavaSource(String varName, Writer out) throws IOException { 24 offset.dumpJavaSource("offset", out); 25 out.write("final int " + varName + " = "); 26 if (baseRegister == 15) { 27 out.write("cpu.getPc()"); 28 } else { 29 out.write("R[" + baseRegister + "]"); 30 } 31 out.write(" + offset;\n"); 32 } 33 }