U.S. stocks ended a three-day decline Wednesday after Ben Bernanke said the Federal Reserve was prepared to offer another stimulus if the economy gets worse, CNNMoney reports. The Fed chairman also said the U.S. would pay bondholders before Social Security beneficiaries if the White House and Congress failed to reach an agreement to raise the federal debt ceiling before the default deadline of August 2.

The Dow Jones Industrial Average gained 0.4 percent, or 45 points, while the S&P 500 rose 0.3 percent, or 4 points. The Nasdaq climbed 0.5 percent, or 15 points. "Bernanke came out and said that the Fed has the tools to support economic growth, and is ready to use them," Timothy Ghriskey, chief investment officer at Solaris Asset Management, told CNN. "That's giving investors confidence."

Stocks gained a full percentage point after Bernanke's testimony before the House financial services committee, Reuters's Pedro da Costa and Mark Felsenthal report. "We have to keep all the options on the table," Bernanke said in response to a question of whether the Fed might launch a third bond-buying program. "We don't know where the economy is going to go." QE2, the Fed's second $600 billion bond-buying program, ended last month. "The market wasn't thinking there would be any mention of QE3 whatsoever and here we're finding out QE3 is not being ruled out. It's a tantalizing headline," Chris Rupkey, chief financial economist at Bank of Tokyo-Mitsubishi, told Reuters.