if a cop asks you your name do you have to give it to them.
Yes. That is part of what's considered reasonable detainment and law enforcement.
Criminal Defense Attorney
In the state where I practice, Arizona, and in most states to my knowledge, it is unlawful to refuse to provide your name to police, in circumstances where the police have lawfully detained you based on reasonable suspicion that you have committed a crime. You may not be compelled, however, to answer any other questions by the police. Also, please note that this law would not apply to a routine traffic stop for a non-criminal offense such as speeding or other civil traffic offenses. In a traffic stop, however, you are required to provide a driver license or other form of identification, but you may not be compelled to speak.