The short answer

A compiler can translate what you wrote into machine code, the byte patterns a particular processor knows how to execute. We compiled a C function that adds three to a score. On our Windows x64 build, the first instruction put the new score in a register, a small storage location inside the processor. The second sent control back to the code that called the function. Give the function seven and you get ten.123

Give the scoreboard one job

The scoreboard says seven. Your team sinks a three-pointer. Before you change the board, think about the two numbers you need. Seven is the score before the shot. Three is the value of the shot. Which one should go into a rule you could use at every game?

Here’s the rule in C. Read the middle line aloud as “return score plus three.” The word score leaves a place for whoever calls the function to supply the current score. The three stays written into the rule. We named the function after_three. Give it a whole number and it gives a whole number back.

Where did the plus sign go?

Follow the plus sign. A compiler reads the text according to the rules of C and recognizes an addition whose result must go back to the caller. It chooses an operation that can do the arithmetic on the target processor. We asked Microsoft’s C compiler to generate code for Windows on x86-64, also called x64. On this build it picked an instruction named LEA. We’ll run it in a moment.12

First, where will the numbers go? A register is a small storage location in the processor. Windows x64 has a convention for calls like ours. Put the first whole-number input in the register on the left of our drawing and look for the answer in the one on the right. The names ECX and EAX identify the low 32 bits of those registers. The compiler can choose those locations before it knows the score.3

Now look at the four bytes our compiler put in the object file. A linker packaged that file into a library Windows could load into memory. We checked both files and found the same sequence. Written in hexadecimal, a way of showing a byte with two characters, each a digit from zero to nine or a letter from A to F, it reads 8D 41 03 C3. A disassembler translates the bytes back into instruction names for us. The first three bytes go together. They encode LEA, including the three we wrote in our rule. The last byte, C3, encodes a separate instruction called RET.24

Watch the result register

Now run the function with seven. The caller puts seven in the input register and calls the function. The call also saves a return address, the place in the caller where execution should pick up again. Keep your eye on the result register. Is ten there yet?23

Follow EAX through the call. When does it first hold 10?
On entry
At function entry, ECX holds 7 and EAX still has its prior value. The next instruction is lea.
The caller has supplied 7. EAX still holds a value from before this calculation.
After LEA
After lea, ECX still holds 7, EAX holds 10, and ret is next.
The score is ready. The instruction pointer now points to RET.
After RET
After ret, the input still reads 7 and the result still reads 10. The next instruction is in the caller.
RET changes where execution continues. The caller resumes with 10 already in EAX.

The processor has an instruction pointer that tells it where to fetch its next instruction. On entry it points at the first byte of our function. The processor decodes the three bytes for LEA. Seven is waiting in the input. Whatever is in the result register came from earlier work.2

Run that first instruction. LEA stands for “load effective address.” A processor often needs to add an offset to a base number to work out an address. Our compiler took advantage of that arithmetic. Here LEA takes the input, adds three, and puts the low 32 bits of the sum in EAX. There’s no trip to memory to look up the answer. ECX still holds seven. EAX now holds ten. Where does the instruction pointer point next?2

It points at the last byte. Run RET and watch where execution goes. RET takes the saved return address from the stack, an area of memory used during calls, and puts that address in the instruction pointer. Now the caller is running again. Look back at EAX. The ten was there before RET and it’s still there when the caller resumes.23

Try the same shot with twelve on the board. Which of the four instruction bytes needs to change? We called the very same function with twelve and got fifteen. The new starting score went into the input register. The three was already in the instruction.23

Who does the work if you use an interpreter?

You could give the same scoring rule to an interpreter, a program that reads instructions and carries them out as the program runs. Take CPython 3.12, one implementation of Python. It first compiles Python source into bytecode, a set of instructions designed for the Python interpreter. When the interpreter reaches an addition, its own machine code does the work of figuring out how to add the values it has. The physical processor can run that interpreter because the interpreter itself is executable code.5

Another option is to translate some of the work while the program runs. That’s just-in-time compilation, or JIT. The V8 JavaScript engine illustrates why you might do both. Its interpreter can start on bytecode quickly. If a function keeps getting called, V8 can spend time compiling it into machine code that later calls can run directly. Whether that extra work pays off depends in part on how often the code runs.6

So if you want to find the instructions behind a plus sign, ask two questions. Which processor will run this? And which piece of software is doing the translating? In our scoreboard test we could open the library before the game and point to the exact four bytes. With an interpreter you would follow the interpreter’s work. With a JIT, the machine code you’re looking for might only appear after the game has begun.256