- Why programs need translating
A CPU only runs machine code, so source code must be translated first.
A processor (CPU) can only directly execute machine code — the binary instructions belonging to its own instruction set. But programmers do not write in raw binary; they write in:
- assembly language — low-level, with mnemonics like
LDD,ADD,OUT(one step up from machine code), or - a high-level language — English-like keywords like
if,while,print(e.g. Python, Java).
Neither of these can be run by the CPU as written, so a translator must convert the source code (what the programmer writes) into object/machine code (what the CPU can run).
The three translators in 9618 do this job in different ways — covered next.
- The CPU only executes machine code (binary).
- Programmers write source code in assembly or a high-level language.
- A translator converts source code → object/machine code so the CPU can run it.