Перейти к содержимому

What Does the CPU Actually Do With Your Code?

Fetch Decode

0:00 / 0:00

What Does the CPU Actually Do With Your Code?

40 просмотров · 11 ч назад
Fetch Decode
9 подписчиков
40 просмотров · 11 ч назад
How do computers read code, when the processor can't read at all? I took one line of Python, print("hi"), and followed it down on my Mac until there was nothing left but switches. Python reads your line twice: once as text, then as 22 bytes of bytecode. The chip itself never sees it. It runs the interpreter, a C program that was compiled long before you pressed enter, and printing "hi" takes it a few thousand machine instructions. At the bottom we take apart a real 32-bit add instruction (flip one bit and it subtracts) and build the adder that runs it out of logic gates and transistors. The bytes, the instruction counts and the add instruction were measured on a MacBook Air (Apple M4) with Python 3.14. Chapters 0:00 One line of Python 0:43 Your code is already numbers 1:24 Tokens and a syntax tree 1:55 22 bytes of bytecode 2:42 A program that runs your program 3:46 Compiled, interpreted or JIT 4:32 One machine instruction, bit by bit 5:25 ENIAC, Booth and FORTRAN 5:57 Fetch 6:44 Decode 7:14 Execute and the adder 7:51 Transistors 8:36 Who read your code? Credits "Glen Beck and Betty Snyder program the ENIAC", U.S. Army photo, public domain, via Wikimedia Commons: https://commons.wikimedia.org/wiki/Fi... "Intel Pentium G2020 Ivy Bridge Die Shot.jpg" by cole8888, CC BY 2.0, via Wikimedia Commons (cropped, colour-graded): https://commons.wikimedia.org/wiki/Fi... "Backlit keyboard.jpg" by Colin, CC BY-SA 4.0, via Wikimedia Commons (cropped, colour-graded): https://commons.wikimedia.org/wiki/Fi... People drawings: Open Peeps by Pablo Stanley (CC0). The 1947 Booth page is our own redrawing, not a scan. Sound effects: Mixkit and CC0. Narration voice and music: ElevenLabs. #computerscience #python #programming