What you are asking about is the BIOS (Basic Input Output system). It is called when the computer starts and determines what hardware is connected and if the hardware is sufficient for the system to be able to boot. If not it gives errors such as my personal favorite
Key board not present Press F1 to continue
Once the BIOS determines the system has enough hardware it attempts to boot from the Primary boot device then the secondary etc. Check out this article for more info: Click Here
Your computer motherboard has an EEPROM that stores the BIOS and other another chip that stores the CMOS settings. The BIOS is responsible for the POST and eventually booting the hard drive. This program is written in Assembly.