If the action is by a mortgagee or his assignee against the mortgagor, or anyone holding under him, the defendant may plead payment of the mortgage debt or the performance of the condition of the mortgage, or any matter which might be pleaded to a direct civil action for the recovery of the mortgage debt, except the statute of limitations. The jury must pass upon such answers and must ascertain the amount of the mortgage debt if any is found to exist. If the verdict is for the defendant, judgment must be entered for him; but if the verdict ascertains an amount due on the mortgage debt, judgment must be entered for the plaintiff for the possession of the land and the costs, and the amount of the mortgage debt, as ascertained by the jury, must be stated in the judgment. If, within 30 days after the entry of the judgment, the defendant shall pay to the plaintiff, or to the clerk for his use, such debt, interest, and costs, then a writ of possession must not issue, and the clerk shall endorse upon the face of the record of the judgment the fact of such payment.
Ala. Code § 6-6-282 (1975)