you have two options,strip down the carb piece by piece and clean with gasoline(dont buy expensive chemicals you DONT NEED, i have fixed many broken bikes like this)while checking all parts for wear, check the needles, they should be very sharp, if dull they are shot, option 2 is just to get a cheap rebuild kit, and do it to it. i have a yamaha 650 special with the same problem. starts up, sounds completely perfect, no off noises pinging or anything and races to max rpm without warning. i had the bike off road test driving it, and the throttle opened up all the way making a 60 foot tall rooster tail, and shot me up to about 85 mph instantly from 30..... bad buisness. long story short im in the process of fixing it now(few internal parts needed, under $30)and cleaning the good parts. good luck 
We invite you to introduce yourself by a few sentences if you are new to
this discussion group. Enter your e-mail to join the forum and get notifcations on new messages. Or post your question,
answer or comment as a guest. We have just improved this discussion forum and expect the number of users to increase.
More 1982 Yamaha XS 400 information
Our discussion groups are intended for short messages. We also welcome more extensive motorcycle reviews.
Bikez also recommends that you check out the technical
data and the riders' rating for the 82 Yamaha XS 400.
You can also rate it yourself. Use our efficient motorcycle
classifieds to sell or
buy
this bike. Your motorbike gets a high quality presentation. Ads are free.