Back to projects

42 project

Libasm

A reimplementation of standard functions in Assembly to understand execution closer to the processor.

Stack

  • Assembly
  • NASM
  • C
  • Linux
  • Syscall

Skills gained

  • Understanding the basics of x86_64 Assembly
  • Manipulating registers and respecting calling conventions
  • Interfacing Assembly code with C
  • Using system calls explicitly

Libasm is a low-level project that consists in rewriting several classic libc functions directly in Assembly. It is a short but very formative project, because it forces a precise understanding of calling conventions, registers, memory and interactions with the system.

01 — Low level

Going below C.

Rewriting simple functions in Assembly helps reveal what abstractions usually hide. Every instruction becomes intentional, and a single register mistake can completely change the behavior of the program.

Illustration of Assembly code and CPU registers
Fig. 01
When a three-line C function becomes a tiny crime scene investigation.

02 — Conventions

A challenging journey.

This project was highly instructive for me, especially because I had to make a second attempt before successfully validating it. I was using movsx instead of movzx in ft_strcmp, which caused certain bytes to be interpreted as signed values and could therefore reverse the comparison result for characters beyond standard ASCII.

The dilemma between movsx and movzx in Assembly.
Fig. 02

03 — Understanding

Seeing the machine closer.

Libasm gave me a better intuition of program execution: argument passing, system calls, memory and return values. It is a useful foundation for low-level debugging and security work.

Illustration of a developer observing the internal behavior of a program
Fig. 03
After Libasm, even strlen looks a little more intimidating.