Subjunctive mood is the issue involved. Both of those sentences could have been written in the subjunctive mood as such:
If he were to have asked me, then I would have stayed.
However, for at least 20 years, I've noticed that native English speakers sometimes do not use the subjunctive mood in both informal, and formal, speech. So, it is fair to say that not using subjunctive mood is not incorrect. Rather, the subjunctive mood is exiting the language.
Myself, a native speaker who chooses to use subjunctive mood, I sort of "auto-correct" both these sentences into the same subjunctive mood sentence that I wrote above. Thus they mean the same thing to me:
If he asked me, I would/'d stay.
If he had/'d asked me, I would/'d have stayed.