The Nasdaq closed at a fresh six-month high Tuesday and the rest of the market settled close to the unchanged mark as better-than-expected earnings and gains in the technology sector offset surging crude oil prices.

The technology-laced Nasdaq Composite Index (search) finished at a fresh six-month high, rising 7.72 points, or 0.36 percent, to end at 2,143.15, its highest close since Jan. 3. The broader Standard & Poor's 500 Index (search) advanced 2.77 points, or 0.23 percent, to finish at 1,222.21. But the Dow Jones industrial average (search) edged down 5.83 points, or 0.06 percent, to close at 10,513.89, marking the end of a three-day rally.

"Some of the real strength in the market has been in the tech issues, which seem to be entering a better cycle," said Rick Meckler, president of Libertyview Capital Management, a Hoboken, New Jersey-based investment firm with $2 billion under management.

Microsoft Corp. (MSFT), up 1.3 percent, gave the biggest boost to both the Nasdaq and the Standard & Poor's 500, while International Business Machines Corp. (IBM), up 1.4 percent, limited the blue-chip Dow's decline.

Microsoft shares rose 32 cents to $25.61 on Nasdaq. Cisco Systems Inc. (CSCO), also among the Nasdaq's biggest gainers, climbed 1.2 percent, or 24 cents, to $19.78. IBM's stock, up $1.08 at $80.04 in New York Stock Exchange trading, was among the Dow's biggest percentage gainers.

Banking shares were helped by news TD Banknorth Inc. (BNK) agreed to buy Hudson United Bancorp Inc. (HU) in a $1.9 billion cash-and-stock deal.

New Jersey-based Hudson surged 11 percent, or $4.14, to $41.64. The deal, due to close in the first quarter of 2006, would create a strong regional bank in New England, upstate New York and New Jersey. TD Banknorth Inc. dropped 86 cents to $29.10.

"On balance, things are going well, but the mood is still very, very guarded," Hugh Johnson, chairman and chief investment officer of Johnson Illington Advisors, said of stocks. "Confidence in the market is improving, but it's improving in very small steps because there's still risks out there, like oil prices."

But even a good day for technology stocks could not completely dispel nervousness about energy costs. A surge in oil prices sapped investor confidence throughout the day. U.S. crude oil futures for August delivery settled up $1.70 at $60.62 on the New York Mercantile Exchange (search), after hitting a session high at $61.25.

High oil prices weigh on equities because they drive up corporate costs and slow down consumer spending.

Oil's rise weighed on economically sensitive blue-chip stocks, including 3M Co. (MMM), down 1.7 percent at $74.87, and Caterpillar Inc. (CAT), down 1 percent at $98.96.

Analysts were pleased that the market did not sell off heavily after the previous sessions' gains, especially with oil prices climbing sharply.

"Really, the market is behaving well, just backing and filling after three big days," said Bryan Piskorkowski, market analyst at Wachovia Securities. "What we need now is good economic data and good earnings if we want this rally to keep going."

Strong profit reports from soft-drink maker PepsiCo Inc. and biotechnology company Genentech Inc. boosted confidence as the earnings season gets into high gear.

PepsiCo (PEP) rose 75 cents to $54.60 as sales of its Quaker Foods cereals and products boosted earnings by 13 percent over the previous quarter. The soft drink and snack food company beat Wall Street profit forecasts by 3 cents per share. The company also reiterated its previous forecasts for full-year earnings.

Genentech (DNA) shares advanced 2.9 percent, or $2.39, to $85.89 a day after the company reported second-quarter revenue and earnings that exceeded Wall Street forecasts.

"Earnings season appears to have gotten off to a good start," said Stephen Massocca, president and head of trading at San Francisco-based Pacific Growth Equities.

With most pre-announcements done, Massocca said, reports are likely to meet or beat Wall Street expectations.

"Anybody who's got bad news has been rushing to get it out," he said. "No one is sitting on bad news for fear of a visit from (New York Attorney General) Eliot Spitzer."

Analysts also noted Wall Street is expecting fairly modest earnings growth for the quarter.

Industrial conglomerate 3M Co. (MMM) and aircraft manufacturer Boeing Co. (BA) both fell. 3M slipped 0.8 percent to $75.52 and Boeing fell 0.8 percent to $64.46, both on the NYSE.

Shares of Sirius Satellite Radio Inc. (SIRI) dropped 2.5 percent to $6.93 on the Nasdaq. UBS lowered its investment rating on the subscription radio company to "neutral" from "buy," citing valuation, MarketWatch reported on its Web site.

Online brokerage Ameritrade Holding Corp. (AMTD) said its earnings rose 20 percent in the latest quarter, meeting analysts' profit estimates, and said it was on track for a record year. Ameritrade added 37 cents to $19.28.

Wall Street firm Bear Stearns Cos. Inc. (BSC) slipped 7 cents to $106.71 after it said in a regulatory filing it may pay $200 million or more to settle charges brought by the Securities and Exchange Commissionthat the company helped hedge funds improperly trade shares of mutual funds. Bear Stearns said it added $100 million to its legal reserve to cover the costs.

Shares of Home Depot Inc. (HD), a Dow component and the top U.S. home improvement chain, shot up 2.5 percent, or $1.00, to $41.30 after brokerage Jefferies & Co. raised its rating on the retailer to "buy" from "hold."

Bonds edged lower as stocks held on to their gains, with the yield on the 10-year Treasury note rising to 4.14 percent from 4.10 percent late Monday. Much of the bond market's weakness was attributed to the dollar, which fell against most major currencies. Gold prices rose.

Trading was fairly active, with 1.46 billion shares changing hands on the New York Stock Exchange, matching the daily average for last year. About 1.66 billion shares were traded on Nasdaq, below the 1.81 billion daily average last year.

The number of shares advancing in value exceeded the number declining by a ratio of more than 9 to 7 on the NYSE and by 16 to 15 on Nasdaq.

The Russell 2000 index of smaller companies was down 0.95, or 0.14 percent, at 670.79, edging off of its all-time high set Monday.

Overseas, Japan's Nikkei stock average rose 0.15 percent. In Europe, Britain's FTSE 100 closed down 0.48 percent, France's CAC-40 dropped 0.18 percent for the session, and Germany's DAX index fell 0.22 percen

Reuters and the Associated Press contributed to this report.