Analysis of the resistive switching phenomenon in MOS devices for memory and logic applications