How can the same eight bits tell one processor to add and another to subtract?
Suppose you send the same eight bits to two classroom computers in Leeds. One processor adds two to a running total. The other subtracts two. How can the bits stay the same while the result changes?
You already know the operating system helps launch an app. When you open a calculator, the operating system arranges for program instructions to be loaded from storage into main memory. The processor can then read those instructions from memory.
Watch imaginary processor A fetch the bits one zero one one, zero zero zero one. It decodes them as an instruction to add one to its running total. Then it executes that instruction, changing the total from six to seven.
Processor A has just read the bits from memory. The total is still six. Which stage works out that these bits mean add one? Pick the stage that gives the bits their meaning.
Give both imaginary processors one zero one one, zero zero one zero. Processor A decodes it as add two. Processor B decodes it as subtract two. These binary instructions are machine code. Each processor’s instruction set defines the instructions it supports and the bit patterns that represent them.
Start both processors at eight and give them the same pattern. On processor A, the pattern means add two, so eight plus two is ten. On processor B, it means subtract two, so eight minus two is six.
This time, both processors start at five. They each receive one zero one one, zero zero one zero. Use the same two decoding rules as before, then pick the pair of final totals.
A compatible processor runs machine code directly. Copied bits can decode differently. In assembly, add two on processor A maps to one machine instruction. You might use assembly for direct hardware control. High-level code needs translation, but it’s easier to write apps with and can be translated for different processors.
An assembler turns assembly into machine code before execution. A compiler translates the whole high-level program before it runs and can produce an executable file. An interpreter translates and runs high-level code one statement at a time. You need the interpreter each time you run the source program.
If an exam asks you to explain one advantage of using a compiler rather than an interpreter, think about sharing an app. Compile it before you share it, then send the executable. On a compatible computer, the user can run it without having to translate the source code each time.