import java.util.Scanner; import java.io.File; /** * A class to model a simple 4-bit Virtual Machine. * @author cs416 * @version 2 */ public class VM { private int ip; private int is; private int r0; private int r1; private int[] memory; //additional variables as needed /** * Load the program instructions from the specified file path. * throws an IllegalStateException if the program file cannot be loaded. * reads instructions from the file until end of file or a maximum of 16 * values have been read * @param progFilePath the path of the program file to load into the VM */ public VM(String progFilePath) throws IllegalStateException { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * For testing purposes - initialize the VM to the array. * The array is in the format {ip, is, r0, r1, m0, m1, .... m15} * @param m the imitialization array */ public VM(int[] m) { ip = m[0]; is = m[1]; r0 = m[2]; r1 = m[3]; memory = new int[16]; System.arraycopy(m, 4, memory, 0, 16); } /** * Turn debug mode on (VM details are printed during step. */ public void debugModeOn() { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * Turn debug mode off (VM details not printed during step). */ public void debugModeOff() { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * Is the VM running. * @return boolean */ public boolean isRunning() { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * Perform a single step (fetch & execute) of the VM. */ public void step() { throw new UnsupportedOperationException("TO BE IMPLEMENTED"); } /** * String representation of the CPU. * @return String */ @Override public String toString() { return String.join( "\n", ".--------. .--------.", String.format("| IP: %2d | | IS: %2d |", ip, is), "'--------' '--------'", ".--------. .--------.", String.format("| R0: %2d | | R1: %2d |", r0, r1), "'--------' '--------'", "", ".-------------------.", String.format("| %2d | %2d | %2d | %2d |", memory[0], memory[1], memory[2], memory[3]), "|----+----+----+----|", String.format("| %2d | %2d | %2d | %2d |", memory[4], memory[5], memory[6], memory[7]), "|----+----+----+----|", String.format("| %2d | %2d | %2d | %2d |", memory[8], memory[9], memory[10], memory[11]), "|----+----+----+----|", String.format("| %2d | %2d | %2d | %2d |", memory[12], memory[13], memory[14], memory[15]), "'----+----+----+----'" ); } }