US stocks ended mostly higher led by gains in the Nasdaq and chipmakers as investors sought bargains after a sharp selloff