The S&P 500 and the Nasdaq fell on Tuesday as investors booked recent profits in the tech sector, while a weaker-than-expected reading on a measure of consumer confidence sparked caution about a pick-up in spending.

Technology shares fared worse than the broader market as investors sold recent winners, and Baidu Inc's disappointing outlook added to the negative tone. The semiconductor index <.SOXX> shed 2.5 percent.

But the Dow clung to a modest gain as shares of Exxon Mobil and Chevron , both set to report quarterly results later this week, rose on the back of BP Plc's strong earnings.

The Dow Jones industrial average <.DJI> gained 14.21 points, or 0.14 percent, to close unofficially at 9,882.17. The Standard & Poor's 500 Index <.SPX> dropped 3.54 points, or 0.33 percent, to end unofficially at 1,063.41. The Nasdaq Composite Index <.IXIC> fell 25.76 points, or 1.20 percent, to finish unofficially at 2,116.09.

(Reporting by Rodrigo Campos; Editing by Jan Paschal)