Gates was a pretty accomplished coder. He famously wrote the bootloader for his Basic interpreter by hand on the plane trip to Altair. Microsoft bought DOS out of expedience, not because they were incapable of developing it on their own.
[1] https://people.eecs.berkeley.edu/~christos/papers/Bounds%20F...
Only full on Gates program I've ever heard of is Donkey.bas
Gates was responsible for writing the first Altair Microsoft BASIC interpreter, except the bootloader, the software for the Kyotronic clones (designed in collaboration with Kay Nishi and licenced to Kyocera, Tandy and others).
Gates also had ample experience in programming minicomputers such as DEC PDP series together with Paul Allen.
You can read all about it in all the Bill Gates biographies out there.