Stocks gained in a holiday-shortened session on Tuesday, lifted by fresh takeover talk and after a report suggesting Apple Inc. will generate fat profit margins on its iPhone.

Deal news again contributed to the gains. Shares of Wendy's International Inc. rose 2.7 percent to $38.39 after billionaire investor Nelson Peltz said his Triarc Cos. Inc. would be a natural, strategic buyer of the fast-food chain.

A report showing that factory orders, excluding the volatile transportation sector, rose in May added to optimism about the economy.

Tech shares gained, lifting the Nasdaq to a 6 1/2-year high, after technology research firm iSuppli said Apple's most expensive iPhone model could deliver a profit margin of more than 55 percent.

I think you could definitely say it is related to the iPhone, and it is influencing tech stocks, said Warren Simpson, managing director at Stephens Capital Management in Little Rock, Arkansas. It's a very sensitive market, but the economy is percolating along. Momentum's on our side.

The Dow Jones industrial average was up 41.87 points, or 0.31 percent, to close at 13,577.30. The Standard & Poor's 500 Index was up 5.44 points, or 0.36 percent, to finish at 1,524.87. The Nasdaq Composite Index was up 12.65 points, or 0.48 percent, to end at 2,644.95.

Apple's stock rose 4.9 percent to $127.17 and was the biggest contributor to the Nasdaq 100 index's gain.

Wendy's stock gained 2.7 percent to $38.39 on the New York Stock Exchange.

New orders at U.S. factories fell 0.5 percent in May, the first drop in four months, the Commerce Department said. The decline in May was much smaller than what economists had forecast.

Excluding transportation, May factory orders rose 0.7 percent.

The session ended early at 1 p.m. (1700 GMT) before Wednesday's U.S. Independence Day holiday, when financial markets will be closed all day.

In other economic news, the National Association of Realtors' Pending Home Sales Index, based on contracts signed in May, unexpectedly fell to its lowest level since September 2001. Wall Street analysts polled ahead of the report were expecting the May index to rise.

The Dow Jones U.S. Home Construction Index was down 1 percent following the data. Before the report, shares of home builders were among the session's top performing subgroups.

Among other stocks that bucked the day's upbeat trend, Caterpillar Inc dropped 3.1 percent to $77.99 after MarketWatch reported that UBS had cut its rating on the diversified manufacturer's stock.

Ford Motor Co. fell 2.3 percent to $9.42 after it said late on Monday it is offering a premium to holders of its 5-year-old debt securities to convert them to common stock, a move that could hit the automaker's third-quarter results.

Trading was light on the NYSE, with about 765.6 million shares changing hands, far below last year's estimated daily average of 1.84 billion shares, while on the Nasdaq, about 1.08 billion shares were traded, well below last year's daily average of 2.02 billion.

Advancing stocks outnumbered declining ones by a ratio of about 2 to 1 on the NYSE and by 16 to 13 on the Nasdaq.