Explain the role of an operational amplifier (op-amp) and how you would design a basic comparator circuit.