The laws relating to the flag of the United States of America are found in detail in the United States Code. Title 4, Chapter 1 pertains to the flag; Title 18, Chapter 33, Section 700 regards criminal penalties for flag desecration; Title 36, Chapter 3 pertains to patriotic customs and observances. These laws were supplemented by Executive Orders and Presidential Proclamations.
http://www.ushistory.org/betsy/flagcode.htm
Conduct During the playing of the national anthem (including placing the hand over the heart) is detailed in:
United States Code Title 36
§301. National anthem
Designation. The composition consisting of the words and music known as the Star-Spangled Banner is the national anthem.
Conduct During Playing During rendition of the national anthem
when the flag is displayed
individuals in uniform should give the military salute at the first note of the anthem and maintain that position until the last note;
members of the Armed Forces and veterans who are present but not in uniform may render the military salute in the manner provided for individuals in uniform; and
all other persons present should face the flag and stand at attention with their right hand over the heart, and men not in uniform, if applicable, should remove their headdress with their right hand and hold it at the left shoulder, the hand being over the heart; and
when the flag is not displayed, all present should face toward the music and act in the same manner they would if the flag were displayed."