The concern has been that "the Fed was going to dial the (stimulus) down to zero regardless how the economy was doing," said Phil Orlando, chief market strategist at Federated Investors. "I don't think that's the case at all...the Fed is going to evaluate the economic landscape," before it cuts its stimulus, Orlando said.
The Standard & Poor's 500 index climbed 4.65 points, or 0.3 percent, to 1,680.91. The Nasdaq composite rose 11.50 points, or 0.3 percent, to 3,610.
The Dow Jones industrial average rose 18.67 points, or 0.1 percent, to 15,470.52.
The Dow was held back by American Express and Caterpillar. The credit card company's stock slumped $1.47, or 1.9 percent, to $76.80 after European regulators proposed to cap the lucrative processing fees the card company imposes.
Caterpillar fell $1.50, or 1.7 percent, to $86.67 after prominent short-seller Jim Chanos said he was shorting the stock because it was exposed to a slump in the mining industry. In a presentation at the 'Delivering Alpha' conference, broadcast by CNBC, Chanos said Caterpillar was "tied to the wrong products, at the wrong time."
Bernanke's comments had a stronger impact on the Treasury market than on the stock market.
The yield on the 10-year Treasury note fell to 2.49 percent from 2.53 percent late Tuesday as investors bought U.S. government bonds. The yield has been declining since July 5, when it surged to 2.74 percent after the government reported that hiring was strong in June.
If Treasury yields climb too fast, it worries stock investors because of the impact that rising interest rates have on the wider economy. For example, higher mortgage rates, which are linked to Treasury yields, would slow demand for homes.
The stock market has climbed back to record levels in July following its brief slump in June, when the S&P 500 logged its first monthly decline since October on concern that the Federal Reserve would ease back on its economic stimulus too quickly. The S&P 500 has gained 4.7 percent in July after falling 1.5 percent in June. It climbed to a record 1,682 on Monday.
The index is up 17.9 percent this year, and stocks could head higher still as the economy improves in the second half of the year, says Rob Lutts, chief investment officer at Cabot Money Management.
"Expect better things," said Lutts. "The market's going to churn its way higher from here."
Investors are also keeping an eye on company earnings during one of the busiest weeks for second-quarter profit reports.
Bank of America rose 39 cents, or 2.8 percent, to $14.31 after it reported surging earnings for the period, helped by cost-cutting and investment banking gains. Bank of New York Mellon gained 57 cents, or 1.9 percent, to $30.92, after the bank posted earnings that beat analysts' expectations. Net income surged in the second quarter as market conditions improved and it collected more fees for managing investments.
Banks and financial companies are expected to report the strongest earnings growth of all S&P 500 companies, according to data from S&P Capital IQ. The growth for the sector is expected to reach almost 20 percent, according to the data provider. That compares to the average growth of 3.4 percent forecast for all companies.
In commodities trading, the price of crude oil rose 48 cents to $106.48 a barrel. Gold fell $12.90, or 1 percent, to $1,277.50 an ounce.
The dollar rose against the euro and the Japanese yen.
Among other stocks making big moves Wednesday:
Yahoo rose $2.78, or 10.3 percent, to $29.66 after the company reassured investors that it would keep buying back its own stock. The internet company had already spent $3.6 billion buying back about 190 million of its shares since last year. The stock is trading at its highest in more than five years.
DuPont rose $2.87, or 5.3 percent, to $57.25, after the activist investor Nelson Peltz told CNBC that his fund had bought a big stake in the company. Peltz was also speaking at the Delivering Alpha conference.
Mattel fell $3.17, or 6.8 percent, to $43.16 after its second-quarter net income fell 24 percent, hurt by weak sales in North America and continued softness in Barbie sales, as well as an asset impairment charge.
St. Jude Medical surged $2.54, or 5.2 percent, to $51 after the medical device maker reported better-than-expected second-quarter earnings on higher sales of its heart-shocking implants.