Hacker News new | ask | show | jobs
by bx_lr 5473 days ago
Quite a bit of stuff is done in assembly:

- Low level processor set up: MMU, TLB, caching etc.

- Early stage boot code.

- Using instructions that are not normally accessible in C. For example, SIMD instructions, count leading zeroes, some bitwise operations.

- Interrupt handlers, interrupt masking.

- Entry and exit to low power modes.

- Entry and exit to hypervisor and other such virtualized modes.

- Sequences to turn on/off MMU.

- System calls.

- Locks for mutual exclusion, critical sections.

- Instruction level optimization in some algorithms.

- Anything that requires stack control or setup (packing arguments, green threads, etc).

- Machine code generation in compilers.

Some people prefer inline assembly and a lot can be achieved by C macros and inline assembly. Personally I prefer naked assembly functions in .s file, it is more readable and requires less tricks.

I rarely see assembly being used for performance. Most of the time the use of assembly is limited only to hardware level interaction that is normally not possible with C.

Even though writing assembly is not that common, the need to read is:

- Debugging on-target code with hardware debugger without having symbols and source available.

- Low level crash dumps (CPU context).

- Staring at disassembly in general.