It turns out there were two problems……firstly, the cmos battery was bad and I swapped it out. Secondly, there was problem with the ram slot (probably because of humidity as I live in Mumbai which is quite humid). I swapped out the slot as I had a single 16 GB stick installed and hence had a vacant slot. Doing the above steps fixed it.Thank you @aactech for your help and your idea about the cmos battery