Stocks posted gains for the fourth day on Tuesday on growing hopes that Greece will avoid a debt default, adding momentum to the market's recent rebound.

The Nasdaq had its biggest percentage gain since October, while the S&P 500 marked its best day in two months in what investors believe could be continued short-term buying from deeply oversold levels.

The Nasdaq reclaimed positive territory for the year and led the market's advance, boosted by a jump in semiconductor stocks. A semiconductor index <.SOX> shot up 2.5 percent, its best gain since April.

In a vote after the market's close, Prime Minister George Papandreou's cabinet won a vote of confidence. It is seen as the first step in moving closer to a resolution of Greece's debt crisis.

It could pave the way for more aid and also remove a source of constant worry about global banks' exposure to the euro zone's debt problems. The PHLX KBW Bank Index <.BKX> gained 1.1 percent after touching a 52-week high earlier in the day.

If you're an investor, you don't want this Greek debt crisis to touch off another round of financial contagion around the world, said Michael Sheldon, chief market strategist of RDM Financial, in Westport, Connecticut.

Volume was lighter than normal, however, with just 6.69 billion shares traded on the New York, Nasdaq and NYSE Amex exchanges, compared with a daily average of 7.58 billion.

The Dow Jones industrial average <.DJI> rose 109.63 points, or 0.91 percent, to 12,190.01 at the close. The Standard & Poor's 500 Index <.SPX> gained 17.16 points, or 1.34 percent, to 1,295.52. The Nasdaq Composite Index <.IXIC> climbed 57.60 points, or 2.19 percent, to 2,687.26.

The Nasdaq ended Tuesday's session above its 50- and 200-day moving averages, for the first time since May 31.

The Dow and the S&P 500 finished last week with gains after six weeks of declines. The Nasdaq, however, ended the week in the minus column.

The S&P 500 is down 5 percent since its May 2 high.

After nearing its 200-day moving average Monday, the S&P 500 rebounded solidly above the level. Analysts saw 1,360 as the next technical level on the upside.

During the session, the Nasdaq also got a lift from U.S.-traded shares of Research In Motion Ltd , which gained 10.3 percent to $28.55 after falling about 7 percent on Monday.

Among stock gainers, Best Buy Co Inc rose 2.7 percent to $32.38 after the electronics retailer raised its dividend and approved a stock-repurchase plan.

On the downside, Walgreen Co fell 4.2 percent to $43.28 after it failed to renew a deal with pharmacy benefits manager Express Scripts Inc . Express Scripts shares rose 0.4 percent to $54.99.

The Federal Open Market Committee began a two-day meeting, with an announcement expected Wednesday afternoon, followed by Federal Reserve Chairman Ben Bernanke's new conference.

The Fed is expected to cut its growth forecast for 2011, but Bernanke probably will continue to argue the slowdown is temporary.

Advancing stocks outnumbered declining ones on the NYSE by nearly 6 to 1. On the Nasdaq, advancers beat decliners by about 4 to 1.

(Reporting by Caroline Valetkevitch; Additional reporting by Ashley Lau; Editing by Jan Paschal)