SAN JOSE, CALIF. -- For the first time in several years, U.S. semiconductor companies held their ground last year against Japanese rivals, according to a ranking of the world's top chip makers.

Japanese companies captured six of the top 10 positions in 1987, including the top three spots, the same as in 1986.

NEC Corp. of Japan was the world's largest chip maker for the second year in a row, with an estimated $3.2 billion in chip sales, according to Dataquest Inc., the San Jose-based market research company that compiles the annual rankings.

Toshiba Ltd. of Japan, the world's largest supplier of dynamic, random-access memory chips, overtook rival Hitachi Ltd. as the No. 2 chip maker. Hitachi fell to third place.

A Japanese company first took the top ranking in 1985.

The rankings are based on worldwide sales for 1987 and are influenced somewhat by the shifting values of U.S. and Japanese currencies. Because the value of the dollar has fallen sharply against the yen, the Japanese sales are inflated when expressed in dollars.

The biggest gainers in 1987 were companies that supplied chips to computer companies, according to Dataquest.

Intel Corp. of Santa Clara, Calif., which makes the microprocessors that are the heart of many personal computers, moved up three spots and had $1.5 billion in sales, a 51 percent increase when compared with 1986.

Most chip makers showed healthy gains, however. NEC's chip sales grew 21 percent, Toshiba grew 29 percent, and Hitachi grew 21 percent.

National Semiconductor Corp. of Santa Clara fell out of the top 10 despite its purchase of Fairchild Semiconductor Corp. last year. Although National's sales for the last two years were revised to include Fairchild, the company still fell to 11th.

Among other U.S. chip makers, Motorola Inc. of Schaumburg, Ill., finished fourth with sales of $2.5 billion, up 21 percent from 1986; and Advanced Micro Devices Inc. of Sunnyvale, Calif. -- together with Monolithic Memories Inc., which it bought last year -- finished 12th with sales of $1 billion, up 21 percent.