Semiconductor stocks have been down in the dumps this year amid the broader stock market sell-off, and it now appears that a potential slowdown in chip demand is going to further weigh on the sector.

The PHLX Semiconductor Sector has already shed close to 40% of its value in 2022. Not surprisingly, high-flying chipmakers Nvidia (NVDA 4.35%) and Micron Technology (MU 2.20%), which were enjoying a terrific run on the stock market until last year, have witnessed a brutal sell-off this year.

^SOX Chart

^SOX data by YCharts

A turnaround at these chipmakers looks unlikely in the short run as they are struggling on account of weak demand. Nvidia anticipates a $500 million revenue hit this quarter thanks to macroeconomic headwinds that will hurt the demand for its graphics cards. Micron, meanwhile, recently issued an alarming forecast about the health of the memory industry. However, both Nvidia and Micron could overcome the near-term headwinds and get back to winning ways in the long run thanks to the markets they serve.

That's why investors looking to buy a semiconductor stock right now may be attracted by the sharp decline in these two companies. But if you had to buy just one of these two chipmakers, which one should you buy? Let's find out.

The case for Nvidia

Nvidia sent investors into panic mode when it released its fiscal 2023 first-quarter results on May 25. The company reported record quarterly revenue of $8.29 billion which was up 46% from the prior-year period, driven by the impressive growth in the data center and gaming businesses. However, a $500 million hit to Nvidia's revenue this quarter on account of COVID-19 lockdowns in China and loss of sales in Russia has got investors worried.

The company expects gaming revenue to decline sequentially. Still, Nvidia's presence in multiple fast-growing end markets such as data centers, automotive, and the omniverse will help it record healthy year-over-year growth this quarter. Nvidia has guided for $8.1 billion in revenue this quarter, which would be a 28% increase over last year. What's more, analysts expect Nvidia's top line to increase 25% this year to $33.6 billion along with a 22% increase in earnings per share.

So, Nvidia is expected to deliver healthy growth once again in fiscal 2023 despite the headwinds that it is facing. Moreover, the company expects its gaming business to gain momentum in the second half of the year once it launches its new graphics cards. Of course, weak demand from cryptocurrency miners is going to be a near-term headwind for Nvidia, but investors shouldn't forget that only a third of the company's installed base of users is on its latest RTX series cards.

Additionally, gamers upgrading to Nvidia's latest graphics cards are each spending $300 more as compared to older-generation cards. All this indicates that Nvidia's gaming business could regain its mojo thanks to a combination of healthy volumes and higher prices. Throw in other emerging catalysts into the mix, and it won't be surprising to see Nvidia sustain its healthy growth for a long time to come.

The case for Micron Technology

Nvidia is expected to clock healthy growth in the face of adversity, but the same cannot be said about Micron Technology. The company expects its revenue and earnings to contract significantly in the fourth quarter of fiscal 2022.

Micron released its fiscal 2022 third-quarter earnings report on June 30, and investors were quick to look past the company's impressive year-over-year revenue and earnings growth. That's because Micron's earnings guidance of $1.63 per share on $7.2 billion in revenue for the current quarter would be a big drop over the year-ago period's revenue of $8.27 billion and earnings of $2.42 per share. The adjusted gross margin is expected to slide to 42.5% from 47.9% in the year-ago period.

Micron blames the weak demand for memory used in personal computers and smartphones for its predicament. That's not surprising as sales of both of these consumer-centric products are expected to take a hit in 2022, reducing the demand for Micron's memory chips as a result.

But Micron is looking to shift its revenue mix toward faster-growing markets such as data centers, automotive, cloud computing, networking, and graphics. Micron management estimates that it could get 62% of its total revenue from these high-growth markets by fiscal 2025 as compared to 38% in fiscal 2021. The company's reduced reliance on mature markets such as PCs and smartphones could help boost its growth in the long run.

Moreover, investors shouldn't forget that Micron is operating in an industry that's expected to generate $330 billion in revenue by 2030 as compared to $161 billion last year. This explains why analysts are expecting 30% annual earnings growth from the chipmaker over the next half-decade. So, Micron still looks like a solid long-term bet.

Which stock is the better buy?

Both Nvidia and Micron have healthy long-term prospects thanks to the markets they serve. However, Nvidia seems better positioned to weather the downturn as its top and bottom lines are expected to increase nicely this year. Additionally, Nvidia is the dominant player in the graphics card market, while Micron has bigger rivals to contend with in the memory market.

But Nvidia's growth during difficult times comes at a premium since the stock is trading at 39 times trailing earnings. That's much higher than Micron's earnings multiple of just 6. Nvidia's rich valuation makes the stock more susceptible to big stock market declines in case its growth falls below expectations, which is why risk-averse investors may want to avoid the stock.

Micron, on the other hand, is too cheap to ignore given its bright long-term prospects. But the headwinds mean that the stock could offer limited upside in the short run. So, investors looking for a value play and willing to wait for a turnaround in the company's fortunes can start accumulating this beaten-down tech stock before it goes on a bull run.