public int operate(int reg1, int reg2, byte aluControl) {
        int result;

        /*The operation to run is decided.*/
        switch(aluControl) {
            case ALUCodes.ADD:
                result = add(reg1, reg2);
                break;
            case ALUCodes.AND:
                result = and(reg1, reg2);
                break;
            case ALUCodes.NOR:
                result = nor(reg1, reg2);
                break;
            case ALUCodes.OR:
                result = or(reg1, reg2);
                break;
            case ALUCodes.SETONLESSTHAN:
                result = setOnLessThan(reg1, reg2);
                break;
            case ALUCodes.SUBTRACT:
                result = subtract(reg1, reg2);
                break;
            default:
                result = 0;
        }

        /*If the resulting value equals zero, set the zero flag to true.*/
        if (result == 0) {
            zeroFlag = true;
        }

        return result;
    }