Why can one line of Python take several instructions on a bike counter's chip?
At a cycle track in Manchester, a bike counter updates a display. You can write its calculation in one line of Python. So why might the chip need several separate instructions to do the same job?
A program gives a processor instructions to follow. In assembly, you write short instruction names such as add. Before the program runs, an assembler translates each real assembly instruction into one machine-code instruction. The processor runs those instructions, which are encoded as bits.
The Python line says to add three to the count, double the result, then subtract one. Watch the three assembly instructions do those jobs in order. This is how you could write the calculation for this Arm instruction set. It doesn't show the instructions Python actually runs.
You can see one Python line above three assembly instructions. If you assemble those three instructions for this Arm chip, how many machine-code instructions do they become? Pick an answer.
Start with a count of five in register X zero, a small storage location inside the chip. Add three and put eight in X one. Add X one to itself to get sixteen. Finally, subtract one. X one now holds fifteen, the same result as the Python line.
Run the same three instructions again, this time starting with seven in X zero. Add three, double what you get, then subtract one. What number ends up in X one? Pick an answer.
High-level code is usually easier to read, write and change than assembly. It often moves between boards with suitable support, while assembly depends on the instruction set. Assembly gives you more direct control over registers and hardware. A high-level runtime can use extra memory, while assembly lets you tune code size and timing.
Python and assembly are both source code. When you click Run, it's easy to think the CPU reads the Python itself. The CPU only executes machine code from its own instruction set. That's why Python needs translation, and why even assembly needs an assembler.
A compiler translates the whole program before it runs. An interpreter processes and executes statements as the program runs. If a compiler produces a machine-code executable, you can run it again without recompiling. An interpreter lets you try edited code without a separate build step.