Assembly language is best - except when it isn’t
A look at why writing in C often produces more efficient code than hand-written assembly language.
Summary
Colin Walls examines the trade-offs between hand-written assembly and C in embedded firmware, showing cases where modern compilers produce equal or better code. Readers will learn why C often yields smaller, faster, or safer binaries for ARM and RISC-V microcontrollers and when assembly is still appropriate.
Key Takeaways
- Measure performance and code size with real benchmarks before deciding to rewrite C in assembly.
- Leverage compiler optimizations (LTO, PGO) and intrinsics to get near-assembly performance without hand-coding instructions.
- Use assembly selectively for proven hotspots, tight interrupt handlers, or hardware init where compilers fall short.
- Apply disciplined testing and review when mixing assembly and C to avoid calling-convention and ABI bugs.
- Prefer modern C with well-chosen compiler flags for maintainability and portability unless a clear, measured benefit exists.
Who Should Read This
Embedded and firmware engineers with some microcontroller experience who need to decide whether to hand-write assembly or rely on C and compiler optimizations for ARM/RISC-V projects.
Still RelevantIntermediate
Related Documents
- Consistent Overhead Byte Stuffing TimelessIntermediate
- PID Without a PhD TimelessIntermediate
- Introduction to Embedded Systems - A Cyber-Physical Systems Approach Still RelevantIntermediate
- Can an RTOS be really real-time? TimelessAdvanced
- Memory Mapped I/O in C TimelessIntermediate








