After more than eight years of military rule, Pakistan is inching its way toward a civilian government.

"Martial law has to go," said President Mohammed Zia ul-Haq, the general who has ruled Pakistan since an Army coup in July 1977.

"It was only an interim measure for the restoration of democratic institutions. The military took over when the country was in chaos, . . . on the brink of civil war," Zia continued in an interview last week in the Army chief of staff's house. Zia still occupies the house, even though a new, grander presidential palace is available here for his use.

Zia, 61, who has proved to be a wily political leader over the past eight years, had promised a return to democratic rule before, only to go back on his word. Elections, for instance, were scheduled six years ago and then suddenly canceled as Zia, in October 1979, tightened his martial law grip on the country.

This time, however, it appears that the process of moving Pakistan to a civilian administration has developed to a point that it will not be reversed easily, although the limits that might be imposed on this new democratic system and the reaction of political forces that have remained on the sidelines in recent months remain unsettled issues.

The U.S. Embassy here seems to have little doubt about the issue, however, and is reporting to Washington that Zia will return the country to civilian rule by the end of the year.

Nonetheless, Zia is demanding that the new National Assembly pass a series of constitutional amendments that will allow a military security council to overrule actions of the civilian government with which it does not agree. Diplomats here call those amendments Zia's price for lifting martial law.

"Only the martial law courts will be disbanded. The Army will still be in control of everything else," charged Pyaralia Allana, a political leader in Karachi of the Pakistan People's Party. The party was founded by former prime minister Zulfiqar Ali Bhutto, who was overthrown by Zia and later hanged after being convicted of conspiracy to commit murder.

"Lifting martial law will only be meaningful when all the amendments Zia instituted are rescinded. Otherwise, he has just institutionalized martial law," continued Allana, who said he has spent most of the past three years in prison for his support of the Pakistan People's Party and is not allowed by the Zia government to leave the country.

The opposition politicians find themselves in a bind, however. They boycotted the National Assembly elections in February, but voters turned out anyway and gave a new breed of politicians respectable margins of victory. If the opposition politicians continue their boycott in the face of what appears to be overwhelming public support for a return to civilian government, they run the risk of being left out when martial law is lifted.

The new political figures, moreover, are prepared to fight for their positions even if the old-line politicians change their minds and join the fight.

A major unanswered question if martial law is lifted is what will happen to Zia. On the basis of a referendum last December, he can claim a five-year hold on the presidency, but he has yet to say whether he will give up his key power post as chief of staff of the Army, as many in the military and among civilians have urged.

Meanwhile, he has moved a few steps to the background and is promoting the country's new prime minister, Mohammed Khan Junejo, an old-line Moslem League politician. Junejo's picture, for instance, appears frequently in newspapers and on state-controlled television news broadcasts.

"Basically, Zia still calls the shots here," said an experienced western diplomat. "The Army is still very much with him. Junejo by himself has little backing."

The new National Assembly and Senate, feistily determined to be independent after being elected in what generally is agreed was a free and honest ballot in February, have played a key role in pushing Pakistan toward democratic government.

The nonpartisan National Assembly is not afraid to debate controversial issues and take positions at variance with the official government line. It picked Junejo as prime minister and named a speaker of the House, Syed Fakhr Imam, who defeated a candidate favored by the president.

"The process is under way" of moving away from martial law, said one western diplomat with long experience in analyzing Pakistan politics. "Both Zia and the politicians have a vested interest in making it work."

"The National Assembly has a mandate" to return Pakistan to civilian rule, said another western diplomat. "It cannot be denied them. There is just a universal consensus that martial law should be lifted."

But neither Zia nor Junejo would give a timetable for ending martial law. And in separate interviews, the president and the prime minister differed in key aspects on the number of steps needed before military rule will be replaced by a civilian government.

Zia said the end of martial law depends on a series of events taking place, with the key one being National Assembly and Senate passage of a law governing political parties in a way that avoids what he sees as the "chaos" of previous political systems.

When that happens and the controversial set of constitutional amendments is approved, Zia said, "then off goes martial law."

"The signs are good, and we may be able to pull it off," he said over tea in his drawing room. "It's been a long time, but I think we have come a long way. We are over the hump. The question is how do we come down the hill."

Another major concern for Zia is the maintenance of law and order once the military lid is taken off. The police force is openly accused in Senate and National Assembly debates of being both ineffective and corrupt, and there are serious questions of whether it could keep the peace without Army help.

Zia is reported to be especially concerned about religious unrest between Shiite and Sunni Moslems and of the reemergence of labor agitation.

It remains unclear what role the old-line politicians, who so far have remained aloof from the new politics of Pakistan, will play if martial law goes.

There is a view among many observers that the leading opposition coalition, the Movement for the Restoration of Democracy, is losing influence since many members are considering jumping to Zia's new government.

The Pakistan People's Party, considered the country's most popular party, is also fractured and reportedly has lost support. Its leader, Bhutto's firebrand daughter Benazir Bhutto, has been in exile in London for the past 18 months. But she has said she will return to Pakistan with the remains of her brother, Shahnawaz Bhutto, who died in Cannes, France, last month. While allowing her to return, the Zia government appears determined not to let the funeral of Shahnawaz become a political rally for the Pakistan People's Party.

Benazir has inherited much of her father's charisma, however, and political observers here and in Karachi say her return could breathe new life into the party.

If so, there is a chance that Zia will go back once again on his promises to end martial law. One of his main objectives appears to be preventing the Pakistan People's Party from returning to power.

At this point, a group of new political figures and old-line politicians who have cast their lot with Zia don't care whether the old parties participate or not.

Junejo has formed his own bloc in the Assembly -- with 190 of its 237 members acting as the "prime minister's parliamentary group."