Some good answers above, some not so great. Some really bad. I like joseywales reply for the most part, although it's a little overly dramatic.
Knowing the rules of your jurisdiction is always important but in most cases in these 50 states the rules of self defense and defense of another are very much the same.
Naturally, where you are is very important because defending someone during an armed robbery in Tulsa, Oklahoma will generate a different reaction from the police than defending someone in a similar situation in Brooklyn, NY. This assumes your gun is legally carried in both such places, etc; let's not get into that issue.
The use of deadly force is only justified if you believe that you are in danger of being killed or seriously injured or that the same is true of someone else. The problem jurisdictionally is that such behavior is looked down upon, say, in Chicago, and is deemed praiseworthy in, say, Abilene. Even if the rules are the same, more or less, the police and the prosecutors have a very different mindset in these disparate jurisdictions.
Having said that, remembering that you do not have a duty to do anything is equally important.
Having said that, let me note that if you are ever so unfortunate to be in such a situation pulling your gun is very risky business because, as you describe it, you are in the perpetrator's line of fire. So avoiding his attention is very important. So, if you perceive the threat as deadly you are either going to step out of the line of fire, obtaining concealment, hopefully, and prepare to defend yourself if necessary or you're shooting. What you're not doing is having a discussion, meaning you don't shout freeze or anything like that. It's not required and only causes the gunman to focus on you. That is exactly what you do not want to happen.
Or, to paraphrase one of my favorite movie lines, if you're going to shoot, shoot; don't talk.
Except in very unusual circumstances, more fictional than real, the perp is not going to be in cahoots with the clerk. Nonetheless, you are going to be in a firestorm of questions from the authorities and you will have to justify your behavior. When I teach a license to carry handgun class I make it perfectly clear that the only thing you tell police is "I thought he was going to kill me (or him/her)" and then ask for an attorney.
But DO REMEMBER to re-holster your own weapon, or put it down, before the police arrive. Don't be mistaken for the bad guy.
I hope this clarifies some things for you.