Spansion Inc. (NYSE:CODE) shares soared more than 11 percent to $25.57 in extended-hours trading on Monday after Cypress Semiconductor Corp. (NASDAQ:CY) announced the two companies will merge in an all-stock transaction valued at nearly $4 billion. The combined company, post-merger, is expected to generate more than $2 billion in revenue annually. Following the announcement, shares of Cypress, a semiconductor design and manufacturing company, rose more than 5 percent to $11 in after-hours trading.

"This merger represents the combination of two smart, profitable, passionately entrepreneurial companies that are No. 1 in their respective memory markets and have successfully diversified into embedded processing," T.J. Rodgers, president and CEO of Cypress, said in a statement.

Under the terms of the agreement, shareholders of Spansion, which designs, develops and manufactures flash memory microcontrollers, will receive 2.457 Cypress shares for each Spansion share they own. The merger is expected to achieve "more than $135 million in cost synergies" on an annualized basis within three years, both companies said. The combined company will continue to pay 11 cents per share in quarterly dividends to shareholders.

"With unparalleled expertise, global reach in markets like Japan and market-leading products for automotive, IoT, industrial and communications markets, the new company is well positioned to deliver best-of-breed solutions and execute on our long-term vision of adding value through embedded system-on-chip solutions," said John Kispert, CEO of Spansion.

Rodgers will serve as chief executive officer of the combined company while Ray Bingham, currently chairman of Spansion, will serve as the nonexecutive chairman. Kispert will serve as one of four Spansion directors.

The transaction is subject to regulatory approvals and is expected to close in the first half of 2015.