Despite promises to hold elections almost from the day he took control here, Gen. Mohammed Zia ul-Haq has failed during his five years of military rule to establish the foundations needed to restore democracy to Pakistan.

The continuation of an unrepresentative, martial-law government here has aroused concern in the West, especially the United States where the Reagan administration has embarked on a $3.2 billion military sales and economic aid package designed to shore up Pakistan as a front-line defense against Soviet expansion. In dollar value, America's economic aid program here is second only to U.S. assistance to Egypt.

"The fact that Pakistan has a martial-law government has been a source of continued reservations among important sectors of opinion in the United States," U.S. Ambassador Ronald P. Spiers said in a Karachi speech, which is reported to have upset the military rulers here because of its unusual frankness.

While the U.S. ambassador stressed the improved relations between Washington and Islamabad after more than a decade of strain that included the burning of the U.S. Embassy here almost three years ago, Spiers bluntly listed four vulnerable areas, including the Zia government's failure to move ahead with elections.

The other problem areas were Pakistan's clandestine nuclear-weapons program, which Spiers warned could jeopardize the new close ties if the Zia government exploded an atomic device or began reprocessing spent fuel; the flow of illegal narcotics from here to the United States, where 70 percent of illegal heroin sold on the streets now comes from Pakistan, Iran and Afghanistan, and some concern that closer ties with Pakistan would be misunderstood as anti-Indian.

Spiers cited the approaching end of his 30-year career as a U.S. diplomat to explain the frankness of his speech, which was seen here by Pakistanis and diplomats from other nations as a warning to the Zia government that the failure to prepare for a return to democracy could imperil continued congressional support of the U.S. aid program, which arose from the Soviet invasion of neighboring Afghanistan in December 1979.

Pakistanis, however, appear resigned to a continuation of martial-law rule for the foreseeable future, if not under Zia then under some other general who may replace him. Many here believe that Zia's talk of holding elections is aimed at public opinion in the United States and other Western nations, which supply most of the $1.6 billion in foreign aid needed to keep the country going.

Part of what one Pakistani political observer described as "public indifference" to politics seems to stem from the limited level of repression used by the Zia government, as compared to other military dictatorships.

While there are political prisoners--the opposition early this month put the number at 2,300--Pakistanis feel free to talk openly against Zia without fear of midnight arrests or sudden disappearances.

Even Zia's opponents acknowledge that the present government is less harsh and vindictive than in the last years of the constitutionally elected government of Zulfiqar Ali Bhutto, whom Zia ousted in an Army coup July 5, 1977.

Bhutto was hanged two years later.

Zia has been adroit in his dealings with Pakistan's politicians, who, with the possible exception of Bhutto's widow Nusrat and his fiery 28-year-old daughter Benazir, have become ineffectual, spent forces, with few supporters. "They have failed to galvanize the people to their side. I don't think the people see an alternative personality to Zia," said one diplomat.

Even the Movement for the Restoration of Democracy, a coalition of eight political parties including Bhutto's Pakistan People's Party, has failed to gather street support needed to overthrow Zia.

The 58-year-old Army general-turned-president promised when he first seized power to hold elections within months. He acted then as a reluctant ruler forced by widespread civil unrest to take over the country for a short time.

As he finishes the end of what would have been a full five-year term of a constitutionally elected president, Zia now appears more deeply entrenched than ever and gives all signs of having grown to like ruling.

"Over the years," said a senior Western diplomat, "his sense of mission has increased and he sees himself as indispensable." Another experienced diplomat predicted that Zia would still be in power by next July.

He has, furthermore, concentrated the reins of power in his own hands and emerged during the past three years as the unchallenged leader instead of being first among equals in a military junta.

He outmaneuvered the other generals who played lead roles in the coup, sending the most threatening of them to early retirement and placing loyal officers in key military, diplomatic, civil-service and industrial positions.

But Zia also has capitalized on every break, including good weather that, with more than $2 billion in remittances from overseas Pakistanis, has boosted the country's sagging economy, and the Soviet invasion of Afghanistan, which ended his isolation from the West and returned him to the good graces of Arab leaders angered by the hanging of Bhutto despite their pleas for clemency.

There are, however, fundamental problems that Pakistanis and diplomats here believe the Zia government has left untouched. Pakistan, for instance, remains a nation still searching for its identity after almost 35 years of independence, a largely feudal and tribal society with vast linguistic and cultural differences among its four provinces. Zia, a devout Moslem, has offered just one solution for knitting the country together--Islam.

But his emphasis on the ritual of the religion has alienated many middle-class Moslem believers here while attempts to propound specific Islamic laws--especially mandatory collection of a religious tax to benefit the poor--have been divisive, heightening longstanding rivalries between the Sunni and Shiite sects.

His new budget, furthermore, is heavily weighted to the military, with half going to defense, while badly needed social services get short shrift. Family planning, for instance, is moribund because religious scholars cannot agree on whether it is allowed under Islamic law.

Similarly, despite one of the lowest literacy rates in the world--24 percent overall and 11 percent for women, who rarely go to school here--Pakistan devotes 1.7 percent of the gross national product to education compared to 6 or 7 percent for many other developing nations.