How interpreted language code is executed by CPU?

336 views Asked by At

I am trying to understand, how interpreted code is executed by the CPU.

I understand, in compiled language code is converted into binary which targets the CPU, when that binary is executed it's loaded into memory where the CPU program counter(PC) points to the next instructions which are then loaded and executed by CPU. But, how does this happen in the case of an interpreted language? I read many blog posts and SO questions everyone has different answers.

Some say the interpreter converts the bytecode on the fly into machine code, some say CPU executes interpreter which knows how to execute the bytecode. But at the end when each instruction has to be executed by the CPU then how does the CPU get the instructions to be executed.

If this is true that the interpreter converts the bytecode on the fly then how does the program counter knows what will be the next instructions, can instructions be loaded into memory dynamically for the CPU to execute, or entire program needs to be loaded in advance before the CPU starts execution

0

There are 0 answers