awesome-everything RU
↑ Back to the climb

Base CS from zero

From machine code to a language: code and mapping reading

Crux Read assembly and high-level snippets, trace a source-to-machine-code mapping, and tell compilation from interpretation from JIT by what each one produces and when.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at middle altitude — in the sky
◷ 14 min

The clearest way to tell these layers apart is to look at real code and ask: how many machine instructions does this become, and when does the translation happen? Read each snippet and pick the answer a careful engineer would give.

Goal

Practise reading the mapping between layers: assembly to machine code (one-to-one), a high-level statement to many instructions, and the difference compile, interpret, and JIT make to what is produced and when.

Snippet 1 — assembly to machine code

        LOAD  R0, 200    ; opcode 00, R0=0, operand 200
        LOAD  R1, 201    ; opcode 00, R1=1, operand 201
        ADD   R0, R1     ; opcode 10
        STORE 202, R0    ; opcode 01, operand 202
Quiz

On the toy CPU each instruction is 2 bytes. How many machine instructions and how many bytes does the assembler emit for these four lines, and why?

Snippet 2 — one high-level statement

const total = price * quantity + shipping;
Quiz

The three variables are already in memory. Roughly how many machine instructions does this single TypeScript line become, and who decides which ones?

Snippet 3 — three ways to run the same program

A)  gcc add.c -o add   &&   ./add          # produces a native binary, then runs it
B)  python3 add.py                          # interpreter reads and runs the source
C)  node add.js                             # interpret first, JIT-compile hot functions
Quiz

Which statement correctly distinguishes A, B, and C by what gets produced and when?

Snippet 4 — bytecode in between

javac App.java     ->  App.class   (bytecode, not native machine code)
java App           ->  the JVM loads App.class and runs the bytecode
Quiz

What is App.class, and why ship bytecode instead of either source text or a native binary?

Recap

Reading the layers comes down to two questions. How many machine instructions? Assembly is one-to-one; a high-level statement is many-to-one, and the compiler picks the instructions. When does translation happen, and what is produced? A compiler emits a native binary ahead of time; a pure interpreter emits nothing for your program and translates each statement at run time; a JIT interprets first and compiles hot functions to native code on the fly; and bytecode is a portable middle layer the VM interprets or JIT-compiles. Match the snippet to the mechanism and the rest follows.

Continue the climb ↑From machine code to a language: trace a program down the ladder
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources2
expand
  1. 01
  2. 02

Trademarks belong to their respective owners. Editorial reference only.