Assembly vs machine code: the same program, for people and for the CPU
Machine code is what a processor actually executes: instructions stored in memory as binary numbers, each one a pattern of bits that the control unit decodes into actions. Assembly language is the same program written for people: each instruction becomes a short mnemonic such as LOAD or ADD with its operand, and an assembler translates it, almost one to one, into the machine-code bytes. So assembly and machine code describe the same instructions at the same level; assembly just replaces numbers with names, and adds conveniences such as labels for addresses and comments. Machine code is the instruction as bits; assembly is the instruction as a word. One assembly line usually becomes exactly one machine instruction.
What each one is good for
Machine code is the only thing the hardware understands, and reading it in binary or hex is how you see what a CPU really does: which bits select the operation and which name the operand. Assembly is how people write and read programs at that level, for boot code, drivers, performance-critical routines and, above all, for learning how a processor works. Each processor family has its own: x86, Arm, RISC-V and MIPS all have different instructions and encodings, which is why tools such as MARS or RARS are tied to one instruction set.
The difference on a real instruction set, in digiwleea
digiwleea's course CPU has a tiny instruction set where the difference is easy to see: every instruction is one byte, the high four bits the opcode and the low four bits a memory address. The capstone program below is the one the CPU you build runs; the machine code lesson shows how the instruction register splits each byte back into its two nibbles, and assembly language introduces the mnemonics. Act IV builds the parts behind SUB, JMP, JZ and OUT.
The capstone program, both ways
| Address | Assembly | Machine code (binary) | Hex | Meaning |
|---|---|---|---|---|
| 0 | LOAD 14 | 0001 1110 | 1E | Accumulator gets memory[14] |
| 1 | ADD 15 | 0010 1111 | 2F | Add memory[15] to the accumulator |
| 2 | STORE 13 | 0011 1101 | 3D | Write the accumulator to memory[13] |
| 3 | HALT | 1111 0000 | F0 | Stop the clock |
In every byte the first four bits are the opcode (0001 LOAD, 0010 ADD, 0011 STORE, 1111 HALT) and the last four the address. The bytes above are the output of digiwleea's own assembler for this program.
No sign-up is needed to start: open the lab and place your first transistor, or read the free theory course. The account (and the AI tutor) are optional.
More comparisons: Digital logic concepts compared
See for yourself: build a logic gate from transistors in the simulator, then follow the path from sand to an 8-bit CPU.
Open the digiwleea lab →Frequently asked
What is the difference between assembly and machine code?
Machine code is the binary form of instructions that a CPU executes directly. Assembly language writes the same instructions with readable mnemonics and names, and an assembler translates it into machine code, usually one instruction for one instruction.
Is assembly language the same as machine code?
No, but they are very close: assembly is a human-readable notation for machine code. Each processor family has its own assembly language matching its own machine code.
How is assembly converted to machine code?
An assembler looks up each mnemonic's opcode, encodes the operands (registers, addresses or constants) into the bit fields of the instruction format, and resolves labels into addresses.
Can a CPU run assembly language directly?
No. The CPU only runs machine code; assembly must first be assembled into machine code.