Microsoft reported its first quarterly loss in three years, largely as a result of a $7.5 billion write-down for its acquisition last year of Nokia's devices and services business.

Microsoft's net loss for the quarter, the fourth of its fiscal year, was $3.2 billion, compared to $4.6 billion in profit during the same period a year earlier, the company announced Tuesday. That translated into a loss of 40 cents a share. Microsoft's quarterly revenue declined more than 5 percent year over year to $22.2 billion.

Revenue from sales of Windows to device makers fell 22 percent during the quarter, as a result of slower PC sales a year after the end of support for Windows XP.

Microsoft's sales of phone hardware grew, but revenue from Lumia smartphones declined because of increased sales of cheaper devices.

There were glimmers of hope in the midst of the rough quarter. Revenue from Microsoft's Surface tablet business more than doubled year over year to $888 million, driven by sales of the Surface Pro 3 and Surface 3. That's a far cry from 2013, when the company took a $900 million write-down based on an "inventory adjustment" caused by the Surface RT's unpopularity.

The computing and gaming hardware segment, which includes the Surface and Xbox businesses, brought in $1.9 billion in revenue, beating the guidance Microsoft gave last quarter. Xbox sales helped drive that growth, with Microsoft selling 1.4 million consoles.

Nearly 3 million consumers signed up for Office 365 during the quarter, bringing total subscriptions to 15.2 million. Microsoft's Office suite service gained nearly 10 million users over the course of the fiscal year, a good sign for the company's push to get more people paying for apps like Word and PowerPoint on a regular basis, rather than purchasing them once.

The news comes after a few tumultuous weeks for the company. Microsoft announced two weeks ago that it was cutting 7,800 jobs to streamline its smartphone hardware business. The company also transferred technology and employees from the Bing Maps team to Uber and sold part of its display advertising business to AOL.

Next week marks the official launch of Windows 10, the next major update to Microsoft's operating system. Terry Myerson, the company's executive vice president of Windows and Devices, said at the Build developer conference earlier this year that Microsoft plans to have more than 1 billion devices running Windows 10 by the end of its 2017 fiscal year two years from now.