Welcome to Learning Assembly by Solving, a collection of 20 small assembly language programs designed to teach fundamental concepts through practical examples. Each program solves a specific problem, ranging from basic arithmetic to control structures, all written in x86-64 assembly using NASM syntax for Linux systems.
The goal is to learn assembly language by implementing solutions to common programming problems. Each .S
file (e.g., 1.S
, 2.S
, ..., 20.S
) in the root directory corresponds to a question listed below, providing hands-on experience with low-level programming.
Here’s the list of problems solved in this repository:
-
Check if a number is even or odd
Determines the parity of a number using bitwise operations. -
Find the maximum of two numbers
Compares two numbers and outputs the larger one. -
Compare two numbers and print "Equal" if they're equal
Checks equality and prints a message accordingly. -
Add two numbers and print the result
Performs addition and displays the sum as a character/digit (for small results). -
Subtract two numbers and print the result
Computes the difference and outputs it. -
Count from 1 to 5 and print each number on a new line
Uses a loop to print numbers sequentially. -
Print the factorial of 5
Calculates 5! (120) and displays it. -
Sum the numbers from 1 to 10
Adds numbers in a range and prints the total (55). -
Check if a number is a multiple of 3
Tests divisibility by 3 and outputs the result. -
Print the first 5 even numbers
Lists 0, 2, 4, 6, 8 with a loop. -
Reverse a 2-digit number (e.g., 42 → 24)
Swaps the digits of a two-digit number. -
Convert a single digit (0-9) to ASCII and print it
Transforms a digit to its ASCII character for output. -
Print "Positive" or "Negative" based on a signed number
Determines the sign of a number and prints the appropriate label. -
Calculate and print 2^n for small n (like 0–5)
Computes powers of 2 (1, 2, 4, 8, 16, 32) and displays them. -
Check if a number is prime (try for small ones like 2–10)
Tests primality for small integers. -
Store 5 numbers in memory and find their sum
Sums an array of 5 numbers. -
Swap two variables using a temporary register
Exchanges the values of two variables. -
Find the average of 3 numbers
Calculates the integer average of three numbers. -
Print the alphabet A to E using a loop
Outputs A, B, C, D, E on separate lines. -
Take two numbers and print which one is closer to 10
Compares distances from 10 and prints the result.
The repository contains 20 assembly source files in the root directory:
1.S
,2.S
,3.S
, ...,20.S
Each file corresponds to the question number above and contains a standalone program written in x86-64 assembly.
To compile and execute these programs on a Linux system with NASM installed:
-
Assemble:
nasm -f elf64 <filename>.S -o <filename>.o
Example: nasm -f elf64 1.S -o 1.o
-
Link:
ld <filename>.o -o <filename>
Example: ld 1.o -o 1
- Run:
./<filename>
Example: ./1
- NASM: The Netwide Assembler (install with sudo apt install nasm on Ubuntu/Debian).
- Linux: These programs target x86-64 Linux systems using system calls (e.g., write, exit).
Or try online compilers such as https://onecompiler.com/assembly/43dsexwn3
Feel free to fork this repository, submit pull requests, or open issues for suggestions and improvements. Contributions are welcome!
Created as a learning exercise by Max Base to explore assembly language programming. Inspired by fundamental programming challenges adapted to the low-level environment.
Copyright © 2025 Max Base. This project is licensed under the MIT License.