Stallman is simply wrong: that's like saying that stealing a car and stealing a motorcycle are "totally different things" because there is some difference. They are all examples of the concept "intellectual property", though they differ under the law in particular ways. Copyright of books and copyright of computer programs is likewise covered by somewhat different law, but they have something in common. The essential thing that all forms of intellectual property law have in common is that they protect a person's intangible intellectual creations: they are treated like property, just as the fruits of an individual's labor is property.
As far as "how much of the actual code" is the same, you would have to look at the legal code of a particular country. In the US, trademark law is gathered together in Title 15 under Chapter 22; patent law is in Title 35; copyright law is Title 17. Patents and copyrights are similar in being a constitutionally enumerated power of Congress (Art. I, Sect. 8, Cl. 8), the power "To promote the Progress of Science and useful Arts, by securing for limited Times to Authors and Inventors the exclusive Right to their respective Writings and Discoveries". Patents and trademarks are similar in that they are both controlled by the Patent and Trademark Office. All three have in common that they are the based in the common law, and were until the Trademark Cases held to be covered by the Copyright Clause.
From a practical perspective, understanding the intellectual and historical underpinnings of copyright, trademark and patent is probably not useful in understanding software licensing. Instead, it is most useful to understand copyright law and contract law, and perhaps patent law just in case some piece of software is patented (see this for an overview in the US, and this for the UK). The basic idea of software licensing is that only the author can authorize making any copies of their program, and a license is a legal device for stating the conditions under which permission to copy is granted.