Summary:
First, all devices have their own machine code to tell them what to do.
CPU takes a string of bits (machine code - designed by the manufacturer) and output another string of bits that do some special tasks or tell the devices what to do.
'The strings of bits' - intructions, are stored in RAM (random access memory). CPU read (input) these instructions and execute an output. The output maybe tell the hard disk to write somethings. Maybe store somethings to RAM again.