The primary purpose of the address, in "days of yore," was so that people could write to you to ask for a reprint and/or start a correspondence with you about your paper. And most institutions were willing to forward snail-mail if you kept them informed of your current address. All of that is pretty much irrelevant now. So I think the primary answer to your question is to make sure that your address includes an email address that will not expire, regardless of your moves. I know many mathematicians who use a gmail address for that purpose. If instead you use the email address at your current institution, make sure that they will forward email to whatever new address you give them. Beyond that, the other advice on how to list the institution(s) seems reasonable, since institution A deserves some credit for supporting your work, as possibly does institution B if, say, you revised the paper while there.