Standing before the picture hung in the place of dishonor over the toilet, the admiral stabbed the tiled bathroom wall with his forefinger to tap out the type of coded message that had sustained him during 7 1/2 years of isolation and torture in Hanoi's Hoa Lo prison.

In those days when Hao Lo was a fearsome place rather than just a picture in the bathroom, James Bond Stockdale's determination to live and lead was fortified every time he heard a tapped message from a fellow prisoner of war. Now, a president of the Navy War College here, Stockdale is searching for some way to teach navy officers how to withstand the tortures, the threats, the beatings and the fears that he had to teach himself to resist.

Can such qualities be transmitted in the calm setting of a peacetime campus? Stockdale believes they can be, although it is only in the crucible of combat or the desperation of detention that they finally rise to the surface. For him, it was the classic philosophy learned in a graduate course at Stanford, rather than anything taught him at Annapolis, that came back to fortify him against the cruelties of his North Vietnamese captors.

There was the time, for example, when the North Vietnamese handcuffed Stockdale's hands behind his back, locked his legs in heavy irons and dragged him from his dark prison cell to sit in the unshaded courtyard where other prisoners could see what happened to anybody who refused to cooperate. The Navy's official report of Stockdale's imprisonment, based on exhaustive questioning after his release, describes that and other incidents during Stockdale's 2,714 days of captivity from Sep. 9, 1965, to Feb. 12. 1973:

He remained sitting in that position for three days. The sun beat down upon him. Since he had not been in the sun for a long time, he soon felt weak. He yelled for Bao Cao [guard], and the guard struck him from side to side on the face.

The indomitable prisoner communication system provided a great boost to Captain Stockdale's morale at this point as two prisoner dishwashers established voice contach for short words of encouragement in spite of close guard supervision.

The guard on duty decided not to let him sleep, and at one point accused him of dozing, punching Captain Stockdale right and left of the jaw.

As the guard left the stall, Captain Stockdale remembers hearing with pride a towel [snapping out in prison code the letters] GBUJS for God Bless You Jim Stockdale.

THERE ARE LESSONS in that and other prison experiences that Stockdale has decided to distill into an elective course for officers at the Naval War College, starting next fall. Called "Foundations of Moral Obligation," the course that Stockdale himself will teach represents the latest attempt to help American fighting men cope with pressure, including but not limited to that inflicted by captivity. He will try to convey to young officers what teachings got him through his 7 1/2 years of captivity, which began on Sept. 9, 1965, when he parachuted from his damaged A-4 fighter-bomber into a tree. He will try to explain how and why a man can summon up astonishing courage if he has committed himself to integrity - "one of those words which many people keep in that desk labeled 'too hard,'" in Stockdale's words.

There was the day his captors decided to force him to be photographed for a propaganda film:

Escorted by Pig Eye [the POWs' name for one of their guards,] Captain Stockdale marched down to the Heartbreak improvised wash area where he was given a new razor and soap. He knew he had to act quickly, and he had already decided exactly what to do.

Getting down into a hunched position, as if preparing to shave, he frantically started digging with the razor. He began to cut the top out of his hair in sort of an inverse Cherokee in an attempt to make himself unpresentable so that he couldn't be photographed.

In his panic, he actually dug the razor into his scalp several times without feeling it. Pig Eye, who had been busy getting gear together, suddenly realized that Captain Stockdale was not working on his whiskers. He stormed through the door and saw the blood streaming from the cuts in the scalp . . .

Realizing his blunder, Pig Eye jerked Captain Stockdale out of the wash area and rushed back to Room 18 [where two other guards, "Rabbit" and "Chihuahua," were waiting] . . . Captain Stockdale could see their surprise turn into rage as they saw his bloody head and leaped to their feet and to the conclusion that it was a suicide attempt.

Captain Stockdale immediately took a seat on the floor [in the position the guards had so often pushed him into before subjecting him to the wrenching rope torture.]

"No. No. Get up," one of the guards ordered. "Why are you taking your own life? You've got things to do. The senior officer wants to see you tonight."

The guards left him locked up in his cell and rushed out to find a hat to cover the cuts so the film ordered by the prison director could be made on schedule.) Alone for the moment, Captain Stockdale knew he had a problem and would have to act quickly. In panic, he realized that the hat would beat him in spite of his determination. He was not going to be used as a tool, for in his hierarchy of values the very top of the list was "not to betray my fellow prisoners or mislead them."

By this time he was about nine days into a fast and was neither too strong nor too alert. He thought of the honey bucket as a device to cut his wrists. He went over to the corner, glanced at the badly rusted, filthy thing and rejected that idea because of the certainty of infection from the rust and filth.

He glanced at the window-glass panes and thought of breaking a pane and cutting his wrists. But he knew there were Vietnamese close by outside, so he picked up his heavy mohogany stool, and, in Captain Stockdale's own words :

"I just started pounding my face. I bruise easily, and I stood there thinking I could be heard. Pretty soon a crowd of curious civilian [prison] workers were looking in awestruck horror through the panes of glass at this madman standing in the middle of the room pounding his face with the stool.

"I kept working because I knew I would get some swelling. I could feel my eyes coming up.There was a commotion at the door, and here were Chihuahua and Rabbit frantically trying to get back in.

"They finally burst in to find both my eyes almost closed up, my eyebrows and eyelids cut and bleeding and my appearance pretty well unfit for photography."

[The guards rushed out of Stockdale's cell a second time, evidently to tell the prison camp director about the further damage the subject of the film had inflicted on himself.]

His eyes still weren't quite as swollen as he wanted them, so he went to the wall and began pounding his face against the conrete. [When the guards returned and saw Stockdale, Chihuahua asked him:] "What are we going to tell the senior officer?"

"You tell the major," Stockdale replied, "the commander decided not to go."

THE FILM the North Vietnamese had in mind, Stockdale learned later, was to show him talking with a lower-ranking fellow prisoner about the unjustness of the war. The other prisoner would be standing behind a screen so Stockdale would not know he was there. The camera would have photographed the two prisoners from the side so viewers would not notice the screen.

Although Stockdale's heroics frustrated the filming scheme, the North Vietnamese through expert rope torture and other coercion did force Stockdale to write and record statements against his will. Like so many prisoners before him, Stockdale learned that every man - no matter how tough - has a limit of how much pain he can take. But he resisted each time before submitting to keep himself and fellow prisoners from unraveling.

During the Korean War, some American prisoners unraveled completely under brainwashing inflicted by their North Korean captors. In hopes of giving future U.S. prisoners of war a moral guide to cling to, the Eisenhower Administration created a Code of Conduct.

One provision of that code stated: "When questioned, should I become a prisoner of war, I am bound to give only name, rank, service number and date of birth. I will evade answering further questions to the utmost of my ability. I will make no oral or written statements disloyal to my country and its allies or harmful to their cause." The late military columnist and author, S.L.A. Marshall, has said that he was "the penamn" when the code was written.

U.S. soldiers, sailors, marines and airmen have all found they could not, under torture, limit themselves to giving "only name, rank, service number and date of birth." Cmdr. Lloyd M. Bucher, skipper of the spy ship USS Pueblo capture by North Vietnam in 1968, said after his release that the code should be reviewed in the light of the harsh realities of the communist torture. He and other Pueblo crewmen testified that their North Korean interrogators were expert at finding a man's weak point and exploiting it. For Bucher, that proved to be his love for his crew. The North Koreans told him they would shoot each of his crew, starting with the youngest, unless he signed a false confession that he invaded North Korea's territorial waters. Bucher signed.

The fear that they could not stand up under torture and would sign propaganda statements in violation of the Code of Conduct drove some Pueblo and Vietnam War servicemen to attempt suicide. They often went into deep and lasting depression after singing confessions under torture.

U.S. officials decided to review the code against the experience of the Pueblo crew and Vietnam prisoners of war. One suggestion was that the code be liberalized and that the U.S. government declare to the world that it would disavow any future confessions by U.S. servicemen on the assumption they were obtained under duress. Stockdale was among the former prisoners of war who urged to code continue unchanged. He argued that even though experience had shown the code could not be fulfilled completely, it served as a standard for men to try to adhere to in captivity. His hardline stand on how prisoners should behave under pressure impelled Stockdale to file misconduct charges in 1973 against two officers who were imprisoned with him. Navy Secretary John Warner decided against prosecuting.

After assessing the various views on the Code of Conduct, the White House announced last November that President Carter had made one liberalizing change. He deleted the word "only" from the provision which formerly stated: "I am required to give only name, rank, service number and date of birth." The White House said the change was "to reduce guilt feelings in prisoners who are coerced into giving more than name, rank, service number and date of birth."

STOCKDALE, who looks amazingly fit at 54 considering what he went through - except for the stiff left leg which was tron at the knee so savagely by his first captors that it cannot be restored through surgery - said his new War College course will focus on a man's personal code.

Uncomfortable questions to be addressed in the classroom, he said, will include: "What do you think of a [dive-bomber pilot] who pulls off the target high" so anti-aircraft fire does not hit him? "What do you think of a guy who doesn't aim his bombs? Is that the way to lead?"

Stockdale's class will study philosophy and history, not military manuals, to get into the teachings that stayed under him like bedrock after the pressure of prison camp had blown everything else away. The philosophy course he took at Stanford in his thirties, said Stockdale, did him a lot more good in Hanoi than any of the Naval Academy's technical subjects.

The 1st century Greek Stoic philosopher Epictetus "was tailor-made for my predicament," said Stockdale as he walked stiff-legged to the bookshelves lining his second-floor office at the Naval War College: "One proposition in his manual that I remembered was that you're but an actor on the stage and your job is to play well the given part."

Other teachings of Epictetus that came back to the crippled pilot and helped sustain him in captivity included: "Lameness is an impediment to the body but not to the will." Men are distrubed not by things, but by the view they take of them." "It's better to die in hunger, exempt from guilt and fear, than to live in affluence with perturbation."

But instead of digging out such teachings so they can form bedrock in the minds and personalities of today's military officers, complained Stockdale, the wisdom that has stood the test of time is being eclipsed by the theoretical jargon of systems analysis, managerial techniques and modern weaponry.

"We spend most of our time worrying about things that have nothing to do with our profession of arms," he said. Stockdale's students will be directed to read Epictetus' "Enchiridion," the Book of Job, Aristole, Plato, Kant, mill, Sartre, Emerson, Dostoyevsky, Conrad, Kafka, Koestler and Solzhenitsyn.

"I think this is the only way to teach a sophisticated audience 'duty, honor, country.' I'm not trying to make fundamentalists out of them. I'm not trying to make warmongers out of them.

"I'm trying to make more self-confident leaders who will realize half of what comes into their baskets is crap and that they should worry about things that are important."