The source code entered by a programmer goes through a process where it’s translated into machine code – instructions that the CPU understands.
In some languages, the source code is converted into machine code ahead of time via a process called compilation. That machine code is stored as an executable file structured based on the operating system (eg. Portable Executable format for Windows). The program is stored on disk. When the computer receives a particular instruction to load the program, it transfers the machine code from disk to RAM, where it can be accessed by the CPU via electrical signals.
In other languages, the source code is interpreted as machine code at runtime. The program that interprets that code puts the machine code into RAM, and again the CPU accesses it to execute the instructions.
How the CPU gets to the point where it knows to load that data into RAM and/or execute it, is more complicated. Because it’s based upon many layers of abstraction, and following a chain of events like dominos. The CPU is designed to start executing instructions from BIOS/firmware once it’s powered on. From there it eventually loads an operating system, which is just a certain type of program. The OS eventually receives user input to compile a program, store the result to disk, and run it; or load the interpreter form disk, run it, load some source code and execute the required instructions.
Latest Answers