A small learning repository for x86-64 assembly on Linux.
The project contains simple NASM programs that call Linux syscalls directly, plus a tiny C-like library implemented in assembly and exercised from C programs.
hello.asm- printsHello, Assembly!using thewritesyscall.input.asm- reads text from standard input and prints it back.add.asm- reads two numbers, converts them, adds them, and prints the result.reverse.asm- reads text and prints it reversed.strcmp.asm- standalone string comparison exercise.minic/- small libc-style routines written in assembly:my_strlenmy_strcmpmy_strcpymy_memcpymy_memsetmy_atoimy_itoa
algorithms/- algorithms written in assembly:bubblesort.asmquicksort.asmbinarysearch.asmlinearsearch.asmselectionsort.asminsertionsort.asmmergesort.asm
use*.c- small C programs that link against selected routines fromminic/andalgorithms/.
This is an educational project, not a production C library. The code favors readability and step-by-step learning over full standard-library compatibility.
- Linux x86-64
- NASM
- GCC
- GNU binutils (
ld)
On Debian or Ubuntu:
sudo apt update
sudo apt install nasm gcc binutilsBuild a program that defines _start, such as hello.asm:
nasm -f elf64 hello.asm -o hello.o
ld hello.o -o hello
./helloYou can use the same pattern for other standalone files:
nasm -f elf64 reverse.asm -o reverse.o
ld reverse.o -o reverse
./reverseBuild an assembly routine as an object file, then link it with a C example:
nasm -f elf64 minic/memset.asm -o memset.o
gcc useMemset.c memset.o -o useMemset
./useMemsetMore examples:
nasm -f elf64 minic/memcpy.asm -o memcpy.o
gcc useMemcpy.c memcpy.o -o useMemcpy
./useMemcpynasm -f elf64 minic/strlen.asm -o strlen.o
gcc useStrlen.c strlen.o -o useStrlen
./useStrlenThis repository includes VS Code tasks in .vscode/tasks.json.
Use Ctrl+Shift+B and choose one of:
Run Assembly- builds and runs the currently opened standalone assembly file.Run C with selected ASM- asks which.asmfiles to assemble, then links them with the currently opened C file.
For direct Linux syscalls on x86-64:
| Register | Purpose |
|---|---|
rax |
syscall number |
rdi |
argument 1 |
rsi |
argument 2 |
rdx |
argument 3 |
r10 |
argument 4 |
r8 |
argument 5 |
r9 |
argument 6 |
Example: write(1, msg, len):
mov rax, 1 ; syscall: write
mov rdi, 1 ; fd: stdout
mov rsi, msg ; buffer
mov rdx, len ; byte count
syscallTo see syscall numbers for your local system:
cat /usr/include/asm/unistd_64.hThis repository is a work in progress for assembly practice. Some files are complete examples, while others are experiments or placeholders for future algorithms.
Planned exercises include:
- More algorithms
- Dynamic memory allocation (
malloc) - Additional libc-style routines
- Brainfuck interpreter
- Lisp interpreter
- CHIP-8 emulator
- Graphics experiments
- PPM/BMP renderer
- ANSI terminal graphics
- 2D renderer
- Sprite engine
- Raycaster
- Mini Doom-like engine
This repository prioritizes:
- readability over clever tricks;
- learning over optimization;
- explicit code over macro magic;
- understanding the ABI and Linux syscalls from first principles.
I use a retro green-on-black VS Code style like in the screenshot because I like the IBM PC 5150 feeling while writing NASM :D
To get the same look:
- Install the
Ac437 IBM BIOSfont, or replace it in.vscode/settings.jsonwith another IBM-style bitmap font. - Install a dark terminal-like color theme. The current settings use
Hacker X - Terminal Zero. - If you want the CRT scanline effect, install a custom CSS loader extension for VS Code and point
vscode_custom_css.importsto the CSS file in.vscode/style.css. - Reload VS Code after changing the font, theme, or custom CSS settings.
The visual settings live in .vscode/settings.json. They are only for appearance; the build tasks are in .vscode/tasks.json.
If you do not want this style, delete everything in .vscode except tasks.json.
I got Ac437 IBM BIOS font from VileR here: https://int10h.org/oldschool-pc-fonts/fontlist/?1
Also, Hacker X - Terminal Zero theme from Hasibur R here: https://marketplace.visualstudio.com/items?itemName=HasiburR.dark-hacker-theme-by-hasibur-r
Suggestions, corrections, and small learning-focused examples are welcome. Please keep examples simple and readable, with comments that help beginners understand what each register and syscall is doing.
