John W. Hinckley Jr. might have been stopped from shooting President Reagan if someone had simply asked him if what he was about to do was wrong, a defense psychologist told a federal jury yesterday.

"If someone had asked him at the moment, 'Do you think it is wrong to shoot the president?' he might have been able to say 'Yes' and he might not have done it," Dr. Ernst Prelinger testified, adding later: "If he had been asked, it might have given him enough structure so the whole act would not have occurred."

Prelinger, the third expert witness to testify on Hinckley's behalf, said under cross-examination that Hinckley "knew in his head" that it was wrong to shoot President Reagan. But, he added, Hinckley did not have that knowledge "in his feelings and in the depths of his thinking and personality."

Prelinger said Hinckley had a "great hope" that he would be shot or killed when he tried to assassinate Reagan.

He testified that Hinckley's choices were dictated by fantasies related to his mental illness. Some of those fantasies, Prelinger told the jury, had been rehearsed months earlier when Hinckley stalked President Carter in Dayton, Ohio, and Nashville.

Hinckley's fantasy to "do a great deed" to impress actress Jodie Foster led him to position himself near the presidential limousine on the day of the shooting and guided his decision to fire, wounding Reagan and three others, Prelinger testified.

Prelinger and two psychiatrists who testified earlier for the defense told the jury that Hinckley suffered from a mental illness at the time of the shooting and as a result could not obey the law.

Like Prelinger, the psychiatrists testified that while Hinckley had an intellectual knowledge that his attack on Reagan was illegal, his emotional understanding was so distorted that he could not appreciate that his acts were wrong.

The prosecution will present testimony next week from its own expert witnesses to support its contention that Hinckley coldly planned his attack on the president and should be held criminally responsible for his actions.

Prelinger testified that Hinckley has a "borderline personality disorder," demonstrated by unpredictable, impulsive acts and a chronic feeling of "aimlessness," major depression, and a "paranoid personality," meaning he is suspicious and always ready to "counterattack."

Those mental illnesses have been catagorized as "ambulatory schizophrenia," Prelinger told the jury.

During cross-examination, Assistant U.S. Attorney Robert R. Chapman ran through a list of Hinckley's responses to some of the true or false questions on a standardized personality test given to Hinckley five weeks after the shooting.

Hinckley was asked whether he believed he was the target of plots, was being followed, was the target of efforts to poison him or control his mind, or was a "special agent of God." In the test, Hinckley said he did not believe any of those things about himself.

When given the statement, "I have often met persons who are supposed to be experts who are no better than I," Hinckley responded: "True."

Hinckley, seated at the defense table, laughed along with spectators in the courtroom when Prelinger said that Hinckley, asked to complete a sentence that began "Rules are . . . " responded, "necessary for the most part. Some rules are applied only to keep bureaucrats employed."

When Hinckley was asked to complete the sentence, "If I can't get what I want . . . " he responded, "I got depressed and moody. I usually ended up getting what I wanted one way or another," Prelinger said.

Meanwhile yesterday, Judge Barrington D. Parker Jr. issued a stern warning to Hinckley's defense lawyer after a deputy marshal interrupted a private bench conference to say that Hinckley wanted to leave the courtroom briefly. When court convened in the morning, Hinckley had tried to take his seat before Parker had taken his place at the bench, a move that also apparently annoyed the judge.

"He is not going to have that door as a revolving door. He either stays or he doesn't stay," Parker said of Hinckley, who twice left the courtroom with Parker's permission Wednesday, and unexpectedly walked out once last week. "I am not going to have it, and I expect him to act as any other defendant in a criminal case when the court comes on the bench.

"You let him know that, because the next time he does it . . . I won't let it go unnoticed," Parker told defense lawyer Vincent J. Fuller, who said he would "caution" Hinckley.

Wednesday, Fuller told Parker that long testimony from psychiatrists had been "difficult" for Hinckley, whom Fuller described as "a very charged individual."