public void terminate() {
        // If we have any branches which should not be taken,
        // we need to create a failure handler for if they were taken.
        if (generateGlobalNotTaken) {
            // XXX: In the future, if we want to set specific flags here,
            // can add more instructions after the label and add an
            // unconditional branch above it to avoid executing the block at
            // the end of the program.
            instructions.add(new Instruction(new Label("nottaken")));
            instructions.get(instructions.size() - 1).appendComment("failure " +
                    "case for wrongly taken branches");
        }

        instructions.add(new Instruction(new HLT()));

        String finalState = "\n";

        // Summarize registers
        for (int i = 0; i < registerFile.length; i++) {
            finalState += "\n# R" + i + " = " + (isRegisterValid
                    (registerFromNumber(i)) ? registerFile[i] : "xxxx");
        }

        // Summarize flags
        finalState += "\n\n# Z = " + (isFlag_z() ? "1" : "0") + " N = " +
                (isFlag_n()
                ? "1" : "0") + " V = " + (isFlag_v() ? "1" : "0");

        // Summarize memory:
        finalState += "\n\n# Valid memory addresses:";
        for (int i : validMemory) {
            finalState += "\n#    mem[" + i + "] = " + memory[i];
        }


        instructions.get(instructions.size() - 1).appendComment(finalState);
    }