Patentable subject matter under U.S. law consists exclusively of "any new and useful process, machine, manufacture, or composition of matter, or any new and useful improvement thereof". 35 USC 101. So, a program may implement a patented process or it may be a piece of a patented machine, but it won't be patentable in itself.