示例#1
0
  public Instructions(String codeIn, int add) {

    String code = codeIn.trim();
    code = code.replaceAll("\\s+", "");
    System.out.println("Code In:\n" + code);

    int len = code.length();
    int chunkLength = 2; // the length of each chunk of code
    for (int i = 0; i < len; i += chunkLength) {
      String chunk = code.substring(i, Math.min(len, i + chunkLength));
      System.out.println("code chunk no. " + (i / 2) + " " + chunk);
      // opCode(chunk); //TODO - need to call this from the memory class I
      // think

      MemoryArray MA = new MemoryArray();
      Memory mem = new Memory();

      // set the memory address and OpCode
      mem.setAddress(add);
      mem.setOpCode(Integer.parseInt(chunk, 16));

      // add the memory object to the memory array
      MA.addMemoryObjects(add, mem);
      // System.out.println("New memory = " + MA.getAddress() + " "
      // + MA.getOpCode());
      add++;
    }
  }