public void emulate()
    {
        ran = false;            // tracks if the whole program ran
        boolean good = true;    // tracks if each step was successful

        // Set the next piece of code to be executed.
        String code = (String) view.getMemoryTable().getValueAt(programCounter, 0);

        // Start executing the program.
        int runTracker = 0;
        while (!ran) {
            if (runTracker > 10000) {

                int n = JOptionPane.showConfirmDialog(
                        null,
                        "Program appears to be taking a while to execute (or it may be"
                        + "\nstuck in an infinite loop). Would you like to terminate?",
                        "Infinite Loop detected",
                        JOptionPane.YES_NO_OPTION);

                if (n == JOptionPane.YES_OPTION) {
                    terminated = true;
                    return;
                }

                runTracker = 0;
            }

            // If we reach "0000", then it's a HLT statement, end execution.
            if (code.equalsIgnoreCase("0000")) {
                ran = true;
                currentCode = code;
                highlightCode();
                return;
            }

            // While the program hasn't reached the end (just a safety measure, not really needed)
            // Do this.. programCounter != programEnd


            good = executeNextStep(code);   // Execute the code
            setRegisters();                 // Set the status registers accordingly
            counter++;                      // Increment counter

            if (code.startsWith("1")) {
                if (findNegative(code.substring(0, 4))) {
                    view.setNegBit(true);
                }
            }

            // Add an error if something went wrong and return.
            if (!good) {
                EmulatorControl.addError(new EmulatorError(">>ERROR<< AN ERROR OCCURED WHEN EMULATING", 0));
                return;
            }

            // Set the next piece of code.
            code = (String) view.getMemoryTable().getValueAt(programCounter, 0);

            // Used when there's an ORG statement in the middle of the program.
            if (code.equals("") && !code.equals("0000")) {
                getBearing();
                code = (String) view.getMemoryTable().getValueAt(programCounter, 0);
            }

            runTracker++;
        }
    }