First, you should make sure there's still a ball of metal at each end. If the ball of metal is gone at either end, you're gonna need a new cable.
If it came off the carburator end, you have to pull the top end of the carb apart, if the spring and throttle slide come out attached, the connection at the carb is fine so you can just put it back together. If the slide and spring stay in the carb, you have to put the spring and slide against the underside of that top piece on the carb and compress it. There should be two holes in the throttle slide right next to each other. Put the cable through the big hole then slide the cable over to the little hole and that will hold the cable. And make sure the metering rod doesn't get lost in the process. Then put the whole thing back together, and don't forget to hook the choke plate to the choke lever.
If it came off at the handlebars, you need to loosen the bolt on the underside of the twistgrip so that it unclamps and slide the whole thing off the handlebar. The grip and the housing should seperate. Relocate the cable end in the notch in the grip and wind the cable over the top of the grip. Then, line the cable housing up in the other piece of the twist grip. Then, to put the grip and other piece together, you need to kind of mess with it until they go together (hard to explain). Then slide the whole thing back onto the handlebar and make sure it works and tighten it up.
Hope this helps (it better) :)