Skip to content

A comprehensive collection of 300 x86-64 assembly language code snippets (using NASM syntax on Linux).

License

Notifications You must be signed in to change notification settings

VoxDroid/assembly-300-snippets

Repository files navigation

Assembly 300 Snippets

Current Repository Progress:

  • Snippets: 180/300
  • Cheatsheets: 180/300
  • Samples: 180/300

Welcome to the Assembly 300 Snippets repository! This project is a comprehensive collection of 300 x86-64 assembly language code snippets (using NASM syntax on Linux) for learning and demonstration. The snippets are categorized into three difficulty levels:

  • Basic (1–100): Foundational concepts for beginners, covering syntax, registers, and basic operations.
  • Intermediate (101–200): More complex techniques, including functions, memory management, and optimization.
  • Advanced (201–300): Specialized applications, such as OS development, reverse engineering, and performance-critical code.

Each snippet resides in its own folder (assembly-300-snippets/XXXX-Title-Name) with a CHEETSHEET.md and SAMPLES.md files, and a README.md explaining the code, its purpose, and usage instructions.

Folder Structure

assembly-300-snippets/
├── assembly-300-snippets/
│   ├── 0001-Hello-World/
│   │   ├── code.asm
│   │   └── README.md
│   ├── 0002-Move-Register/
│   │   ├── code.asm
│   │   └── README.md
│   ├── ...
│   └── 0300-Shellcode-Execve/
│       ├── code.asm
│       └── README.md

Prerequisites

  • Assembler: NASM (sudo apt install nasm on Ubuntu).
  • Linker: GNU ld (sudo apt install binutils).
  • OS: Linux (Ubuntu recommended for compatibility).
  • Build Command: nasm -f elf64 code.asm && ld code.o -o code && ./code.

Contributing

We welcome contributions! Please read our CONTRIBUTING.md for guidelines on how to submit snippets, improve documentation, or report issues.

Community Guidelines

To ensure a welcoming environment, please adhere to our CODE_OF_CONDUCT.md.

Support

For help or questions, refer to SUPPORT.md.

Security

Found a security issue? Please report it following the guidelines in SECURITY.md.

License

This repository is licensed under the MIT License. See LICENSE for details.


Snippet List

Below is the complete list of snippet titles, hyperlinked to their respective folders in this repository.

Basic Snippets (1–100)

# Name Description Snippet Cheatsheet Sample
1 Hello World Print "Hello, World!" to console using syscall.
2 Move Register Move data between registers using mov.
3 Add Numbers Add two numbers using add.
4 Subtract Numbers Subtract two numbers using sub.
5 Multiply Numbers Multiply two numbers using imul.
6 Divide Numbers Divide two numbers using idiv.
7 Compare Numbers Compare numbers using cmp.
8 Conditional Jump Use je for conditional branching.
9 Simple Loop Implement a loop using jmp.
10 Push Pop Stack Push and pop data on the stack.
11 Exit Program Exit with a status code using syscall.
12 Define Variable Define a variable in .data section.
13 Print String Print a string using write syscall.
14 Read Input Read user input from stdin.
15 Bitwise AND Perform bitwise AND operation.
16 Bitwise OR Perform bitwise OR operation.
17 Bitwise XOR Perform bitwise XOR operation.
18 Shift Left Shift bits left using shl.
19 Shift Right Shift bits right using shr.
20 Direct Addressing Access memory using direct addressing.
21 Indirect Addressing Access memory using indirect addressing.
22 Indexed Addressing Access array elements with indexing.
23 Increment Register Increment a register using inc.
24 Decrement Register Decrement a register using dec.
25 Zero Register Zero a register using xor.
26 Flags Register Check flags after arithmetic operation.
27 Jump Not Equal Use jne for conditional branching.
28 Jump Greater Use jg for conditional branching.
29 Jump Less Use jl for conditional branching.
30 Loop Counter Loop using loop instruction.
31 Print Integer Convert and print an integer to stdout.
32 Read Integer Read an integer from stdin.
33 Define Byte Define a byte variable in .data.
34 Define Word Define a word variable in .data.
35 Define Doubleword Define a doubleword in .data.
36 Uninitialized Variable Define variable in .bss section.
37 Move Immediate Move immediate value to register.
38 Load Effective Address Use lea for address calculation.
39 Negate Number Negate a number using neg.
40 Logical NOT Perform logical NOT using not.
41 Swap Registers Swap two registers using xchg.
42 Test Instruction Use test to check bits.
43 Clear Carry Flag Clear carry flag using clc.
44 Set Carry Flag Set carry flag using stc.
45 Check Zero Flag Branch based on zero flag.
46 Signed Multiply Signed multiplication with imul.
47 Unsigned Divide Unsigned division with div.
48 Print Newline Print a newline character.
49 Simple If Else Implement if-else logic with jumps.
50 Nested Loop Implement nested loops.
51 Bitwise Rotate Left Rotate bits left using rol.
52 Bitwise Rotate Right Rotate bits right using ror.
53 Print Hex Number Convert and print number in hex.
54 Read Character Read a single character from stdin.
55 Stack Alignment Align stack to 16 bytes.
56 Compare Strings Compare two strings using cmpsb.
57 Move String Move string using movsb.
58 Clear Register Clear register using mov.
59 Check Sign Flag Branch based on sign flag.
60 Basic Array Sum Sum elements of an array.
61 Modulo Operation Compute modulus using div.
62 Print Boolean Print true/false based on condition.
63 Basic Switch Case Implement switch-case with jumps.
64 Count Bits Count set bits in a number.
65 Reverse Bits Reverse bits in a register.
66 Check Parity Check parity using test.
67 Simple Macro Define a NASM macro for reuse.
68 Print Array Print elements of an array.
69 Copy Array Copy array using loop.
70 Find Max Find maximum in array.
71 Find Min Find minimum in array.
72 Basic Sort Simple bubble sort implementation.
73 String Length Calculate string length.
74 Reverse String Reverse a string in place.
75 Convert Case Convert string case (upper/lower).
76 Basic Stack Frame Set up a basic stack frame.
77 Call Subroutine Call a subroutine with call.
78 Return Value Return a value from subroutine.
79 Local Variable Define local variable on stack.
80 Basic While Loop Implement a while loop.
81 Print Decimal Print number in decimal format.
82 Read String Read a string from stdin.
83 Bitwise Shift Variable Shift a variable’s bits.
84 Check Overflow Check overflow flag after addition.
85 Simple Array Init Initialize an array with values.
86 Basic Pointer Use a pointer to access memory.
87 Swap Variables Swap two variables in memory.
88 Basic Constant Define a constant using equ.
89 Check Even Odd Check if a number is even or odd.
90 Print ASCII Print ASCII character from code.
91 Basic Input Validation Validate numeric input.
92 Simple Counter Count from 1 to N.
93 Basic Factorial Compute factorial iteratively.
94 Fibonacci Sequence Generate Fibonacci numbers.
95 Array Reverse Reverse an array in place.
96 String Concat Concatenate two strings.
97 Basic GCD Compute GCD of two numbers.
98 Prime Check Check if a number is prime.
99 Sum Digits Sum digits of a number.
100 Basic Array Access Access array elements using indexed addressing.

Intermediate Snippets (101–200)

# Name Description Snippet Cheatsheet Sample
101 Function Call Create and call a function with stack frame.
102 Recursive Factorial Compute factorial recursively.
103 Call C Function Call C’s printf from assembly.
104 Floating Point Add Add floating-point numbers using x87 FPU.
105 SSE Vector Add Perform vector addition with SSE.
106 String Copy Copy a string using movsb.
107 Heap Allocation Allocate memory using mmap.
108 File Write Write to a file using syscalls.
109 Thread Creation Create a thread using clone.
110 Inline Assembly Embed assembly in C code.
111 String Compare Compare strings using cmpsb.
112 Array Sort Implement quicksort for array.
113 Matrix Addition Add two matrices.
114 Floating Point Multiply Multiply floats using x87 FPU.
115 SSE Vector Multiply Multiply vectors with SSE.
116 Dynamic Array Allocate dynamic array on heap.
117 File Read Read from a file using syscalls.
118 Function Parameters Pass multiple parameters to function.
119 Stack Frame Cleanup Clean up stack after function call.
120 Loop Unrolling Optimize loop with unrolling.
121 String Tokenize Split string by delimiter.
122 Struct Access Access fields in a C-style struct.
123 Matrix Multiply Multiply two matrices.
124 Recursive Fibonacci Compute Fibonacci recursively.
125 Binary Search Implement binary search on array.
126 Linked List Create Create a linked list node.
127 Linked List Traverse Traverse a linked list.
128 File Append Append to a file using syscalls.
129 Mutex Lock Use mutex for thread synchronization.
130 SSE Matrix Add Add matrices using SSE instructions.
131 String Search Search for substring in string.
132 Memory Copy Copy memory block using rep movsb.
133 Floating Point Divide Divide floats using x87 FPU.
134 Dynamic Stack Alloc Allocate dynamic space on stack.
135 Function Return Struct Return a struct from function.
136 Recursive GCD Compute GCD recursively.
137 Heap Free Free heap memory using munmap.
138 Thread Join Join a thread using syscalls.
139 Matrix Determinant Compute matrix determinant.
140 String Replace Replace characters in a string.
141 Linked List Insert Insert node in linked list.
142 Linked List Delete Delete node from linked list.
143 SSE Dot Product Compute dot product using SSE.
144 File Seek Seek to position in file.
145 Macro Function Define a macro for function-like behavior.
146 Array Filter Filter array based on condition.
147 String Trim Trim whitespace from string.
148 Floating Point Compare Compare floats using x87 FPU.
149 Recursive Power Compute power recursively.
150 Dynamic Matrix Allocate matrix on heap.
151 Bit Manipulation Advanced bit manipulation techniques.
152 Array Map Apply function to array elements.
153 String Format Format string with placeholders.
154 SSE Matrix Multiply Multiply matrices using SSE.
155 File Copy Copy contents of one file to another.
156 Recursive Sum Sum array recursively.
157 Thread Pool Implement a simple thread pool.
158 Struct Array Array of structs in memory.
159 String Parse Int Parse string to integer.
160 Matrix Inverse Compute matrix inverse.
161 Linked List Reverse Reverse a linked list.
162 SSE Vector Normalize Normalize vector using SSE.
163 File Delete Delete a file using unlink.
164 Recursive Binary Search Recursive binary search on array.
165 Macro Loop Use macro for loop generation.
166 String Split Split string into array of strings.
167 Floating Point Power Compute power for floats.
168 Heap Realloc Reallocate heap memory.
169 Thread Synchronization Synchronize threads with spinlock.
170 Matrix Transpose Transpose a matrix using loops.
171 Linked List Sort Sort a linked list.
172 SSE Cross Product Compute cross product using SSE.
173 File Permissions Change file permissions using chmod.
174 Recursive Merge Sort Implement merge sort recursively.
175 String To Float Parse string to floating-point number.
176 Dynamic Struct Allocate struct on heap.
177 SSE Matrix Inverse Compute matrix inverse using SSE.
178 File Lock Lock a file using flock.
179 Recursive Tree Traversal Traverse a binary tree recursively.
180 String Encode Encode string (e.g., Base64).
181 Linked List Merge Merge two linked lists.
182 SSE Vector Distance Compute vector distance using SSE.
183 File Rename Rename a file using rename.
184 Recursive Quick Sort Implement quicksort recursively.
185 String Decode Decode string (e.g., Base64).
186 Dynamic Tree Node Allocate binary tree node on heap.
187 SSE Matrix Determinant Compute determinant using SSE.
188 File Truncate Truncate a file using truncate.
189 Recursive Factorial Tail Tail-recursive factorial.
190 String Hash Compute hash of a string.
191 Linked List Cycle Detect cycle in linked list.
192 SSE Matrix Transpose Transpose matrix using SSE.
193 File Stats Get file stats using stat.
194 Recursive Heap Sort Implement heap sort recursively.
195 String Compress Compress string using run-length encoding.
196 Dynamic Hash Table Implement a hash table on heap.
197 SSE Vector Rotate Rotate vector using SSE.
198 File Monitor Monitor file changes using inotify.
199 Recursive Tree Search Search binary tree recursively.
200 Matrix Transpose Transpose a matrix using loops.

Advanced Snippets (201–300)

# Name Description Snippet Cheatsheet Sample
201 Simple Bootloader Write a minimal bootloader.
202 Kernel Module Create a Linux kernel module.
203 Interrupt Handler Set up an interrupt handler.
204 Memory Allocator Implement a simple heap allocator.
205 Port IO Read/write to hardware ports.
206 Disassemble Binary Disassemble a binary with objdump.
207 Self Modifying Code Write self-modifying code.
208 AES Encryption Implement AES encryption.
209 Shellcode Spawn Write shellcode to spawn a shell.
210 Custom ISA Emulator Emulate a toy instruction set.
211 VGA Graphics Draw pixels in VGA mode.
212 Kernel Syscall Implement custom syscall in kernel.
213 IDT Setup Set up Interrupt Descriptor Table.
214 Page Table Configure a page table.
215 Device Driver Write a simple device driver.
216 Code Obfuscation Obfuscate code with jump table.
217 SHA Hash Implement SHA-256 hash.
218 Shellcode Reverse Shell Shellcode for reverse shell.
219 AVX Vector Add Vector addition using AVX.
220 Simple OS Kernel Minimal OS kernel with boot.
221 Memory Protection Set memory protection with mprotect.
222 Keyboard Interrupt Handle keyboard interrupt.
223 Custom Allocator Advanced custom memory allocator.
224 GPU Shader Write a simple GPU shader.
225 Reverse Engineer Loop Reverse engineer a loop construct.
226 RSA Encryption Implement RSA encryption.
227 Shellcode Inject Inject shellcode into process.
228 AVX Matrix Multiply Matrix multiply using AVX.
229 Simple File System Implement a basic file system.
230 Timer Interrupt Handle timer interrupt.
231 Memory Cache Optimize Optimize code for cache efficiency.
232 Network Socket Create a TCP socket.
233 Code Polymorphism Write polymorphic code.
234 SHA512 Hash Implement SHA-512 hash.
235 Shellcode Bind Shell Shellcode for bind shell.
236 AVX Vector Normalize Normalize vector using AVX.
237 Task Scheduler Implement a simple task scheduler.
238 Page Fault Handler Handle page faults in kernel.
239 Memory Compression Compress memory block.
240 Network Packet Craft a network packet.
241 Anti Debugging Implement anti-debugging techniques.
242 ECDSA Signature Implement ECDSA signature.
243 Shellcode Stealth Write stealthy shellcode.
244 AVX Matrix Inverse Compute matrix inverse using AVX.
245 Process Fork Fork a process using syscall.
246 Exception Handler Handle exceptions in kernel.
247 Memory Encryption Encrypt memory block.
248 Network Server Implement a simple TCP server.
249 Code Encryption Encrypt code section.
250 AVX Dot Product Compute dot product using AVX.
251 Virtual Machine Implement a simple VM.
252 Signal Handler Handle signals using sigaction.
253 Memory Alignment Align memory for performance.
254 Network Client Implement a TCP client.
255 Code Packing Pack code for size optimization.
256 AVX Cross Product Compute cross product using AVX.
257 Process Injection Inject code into running process.
258 Memory Paging Implement basic paging.
259 Crypto Hash Implement a custom crypto hash.
260 Shellcode Loader Load and execute shellcode.
261 Real Time Interrupt Handle real-time interrupts.
262 Memory Decompression Decompress memory block.
263 Network Sniffer Sniff network packets.
264 Code Anti Analysis Anti-analysis techniques for code.
265 AVX Matrix Determinant Compute determinant using AVX.
266 Process Monitor Monitor process creation.
267 Memory Snapshot Take snapshot of memory state.
268 Network Broadcast Send broadcast packet.
269 Code Self Decrypt Self-decrypting code.
270 AVX Vector Distance Compute vector distance using AVX.
271 Thread Scheduler Implement thread scheduler.
272 Memory Virtualization Virtualize memory access.
273 Crypto Stream Cipher Implement stream cipher.
274 Shellcode Obfuscation Obfuscate shellcode.
275 AVX Matrix Transpose Transpose matrix using AVX.
276 Process Fork Exec Fork and exec a process.
277 Memory Tracing Trace memory accesses.
278 Network UDP Implement UDP communication.
279 Code Anti Tamper Implement anti-tamper mechanisms.
280 AVX Vector Rotate Rotate vector using AVX.
281 Kernel Thread Create kernel thread.
282 Memory Sandbox Implement memory sandbox.
283 Crypto Block Cipher Implement block cipher.
284 Shellcode Anti Debug Shellcode with anti-debugging.
285 AVX Matrix Solve Solve matrix system using AVX.
286 Process Hooking Hook a process function.
287 Memory Forensics Analyze memory for forensics.
288 Network Firewall Implement basic firewall rules.
289 Code Signing Implement code signing.
290 AVX Vector Transform Transform vector using AVX.
291 Kernel Debug Debug kernel with breakpoints.
292 Memory Isolation Isolate memory regions.
293 Crypto Key Exchange Implement key exchange.
294 Shellcode Persistence Persistent shellcode execution.
295 AVX Matrix Eigen Compute eigenvalues using AVX.
296 Process Migration Migrate process to another CPU.
297 Memory Encryption AES Encrypt memory with AES.
298 Network Protocol Implement custom protocol.
299 Code Virtualization Virtualize code execution.
300 Shellcode Execve Shellcode to execute a program.