Assembly language

Also known as: assembler language

On this page 7

Assembly language, also called assembler language, is a low-level programming language in which each statement corresponds closely to a single machine instruction of a particular processor architecture. In programming, it sits directly above binary machine code: instead of writing numeric opcodes, the programmer writes human-readable mnemonics such as MOV, ADD or JMP, symbolic register names and labels, and a program called an assembler translates them into executable bytes.

Because the instruction set differs between processor families, assembly language is architecture-specific: code written for x86-64 does not run on ARM or RISC-V without being rewritten. This makes it the opposite of portable programming languages such as C or Rust, yet it remains essential wherever exact control over hardware, timing or code size is required.

How assembly language becomes machine code

The assembler performs a largely one-to-one translation from mnemonics to opcodes. It resolves labels to addresses, encodes operands and addressing modes, and produces an object file that a linker combines with other modules into an executable or firmware image.

Most assemblers make two passes over the source. The first pass collects the addresses of labels, and the second pass emits the final encoding once every forward reference is known. Assemblers also process directives, which are instructions to the assembler rather than to the processor, for example reserving memory or defining constants.

The table below lists the main elements of an assembly source file and their roles.

ElementExampleRole
MnemonicADD, MOV, BEQNames a processor instruction
OperandRegister, immediate value, memory addressData the instruction works on
Labelloop_start:Symbolic address for jumps and data
Directive.data, .byte, .globalControls layout, sections and symbols
MacroUser-defined instruction sequenceReduces repetition at assembly time
CommentText after ; or #Documents intent, ignored by the assembler
Elements of an assembly source file

Disassembly is the reverse process. Debuggers and reverse-engineering tools convert machine code back into assembly, although original label names and comments are lost unless debug symbols are available.

Instruction set architectures and syntax variants

Every assembly language follows the instruction set architecture (ISA) of its target processor, which defines the registers, instructions, addressing modes and calling conventions. The ISA determines how assembly code looks and how much work each instruction performs.

The following table compares widely used architectures from the assembly programmer’s point of view.

ArchitectureDesign styleGeneral-purpose registersTypical use
x86-64CISC, variable-length instructions16 of 64 bitsDesktop and server processors
ARM AArch64RISC, fixed 32-bit instructions31 of 64 bitsPhones, laptops, cloud servers
RISC-VModular open RISC32 (x0 always zero)Embedded chips, research, new SoCs
AVR8-bit RISC microcontroller32 of 8 bitsSmall embedded devices
MIPSClassic RISC32 of 32 or 64 bitsTeaching, legacy networking hardware
Common architectures for assembly programming

Even for one architecture, syntax can differ between assemblers. On x86, Intel syntax writes the destination first (mov eax, 1), while AT&T syntax used by GNU tools writes the source first with prefixes (movl $1, %eax). Common assemblers include NASM, MASM, the GNU assembler and the assembler built into LLVM.

Assembly compared with machine code and higher-level languages

Assembly occupies a narrow layer between raw machine code and compiled languages. It offers full visibility of what the processor executes but provides none of the abstractions that make large programs manageable, such as types, structured control flow or automatic memory management.

The comparison below shows the trade-offs across these levels.

LevelPortabilityDeveloper productivityControl over hardware
Machine codeNoneVery lowComplete
Assembly languageNone across ISAsLowComplete, with readable names
CHigh with recompilationModerateHigh, close to hardware
Rust, C++, ZigHigh with recompilationModerate to highHigh, with safer abstractions
Python, JavaVery highHighIndirect, through a runtime
Assembly language and neighboring levels of abstraction

A common misconception is that hand-written assembly is always faster. Modern optimizing compilers schedule instructions, allocate registers and vectorize loops very effectively, so a skilled programmer usually beats the compiler only in small, carefully measured hot spots.

Where assembly language is still used

Assembly remains necessary wherever a higher-level language cannot express an operation or cannot guarantee the required precision. Most projects use it in small amounts embedded in C or C++ through inline assembly or separate assembly files.

  • Boot code and firmware: setting up stacks, interrupt vectors and memory before C code can run.
  • Operating system kernels: context switching, system call entry and privileged instructions.
  • Performance-critical kernels: cryptography, codecs and math libraries using SIMD instructions such as AVX or NEON.
  • Microcontrollers: cycle-exact timing and code that must fit into a few kilobytes.
  • Security and reverse engineering: malware analysis, exploit research and debugging without source code.
  • Compiler development: verifying and tuning the code that compilers generate.

Many developers never write assembly but still read it regularly. Inspecting compiler output helps explain performance anomalies, confirm that a loop was vectorized or diagnose a crash in an optimized build.

Risks and common mistakes in assembly programming

Because the assembler checks almost nothing beyond syntax, errors surface at run time and often corrupt memory silently. The table lists typical problems.

MistakeConsequenceRemedy
Violating the calling conventionCorrupted registers in the callerSave and restore callee-saved registers
Misaligned stackCrashes in SIMD or library callsKeep the stack aligned as the ABI requires
Wrong operand sizePartial writes and wrong resultsUse explicit size specifiers
Ignoring flags side effectsIncorrect conditional branchesCheck which instructions modify flags
Optimizing without measuringMore complex code with no gainProfile before and after each change
Typical assembly errors and remedies

Assembly code is also expensive to maintain. It must be rewritten for each architecture, so teams usually keep a portable C fallback next to optimized routines and select between them at build or run time.

The simple explanation

A processor only understands long strings of numbers. Assembly language gives each of those numeric commands a short, readable name, such as ADD for addition or JMP for jumping to another place in the program.

Writing in assembly is like giving step-by-step instructions to a very fast but very literal worker. You control every single move, which can make programs small and quick, but you also have to spell out everything yourself. That is why most software is written in friendlier languages, and assembly is kept for the few places where exact control matters most.

How it is used in practice

A firmware engineer at a company that makes industrial sensors works on a battery-powered device built around a 32-bit ARM Cortex-M microcontroller. Almost all of the firmware is written in C, but the startup file is in assembly: it sets the stack pointer, copies initialized data from flash to RAM, clears memory and only then calls the C entry point.

Profiling later shows that a signal-filtering routine consumes about 40 percent of active processor time. After studying the compiler output, the engineer rewrites the inner loop in assembly using the processor’s multiply-accumulate instructions and keeps the C version as a reference for automated tests.

The rewritten loop runs roughly twice as fast, the device spends more time in sleep mode, and estimated battery life improves by several months, while less than one percent of the code base is written in assembly.