assembly-300-snippets

assembly-300-snippets

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

5stars
1forks
5watchers
0issues
1.4 MB
screenshots/
assembly-300-snippets screenshot 1
assembly-300-snippets screenshot 2
assembly-300-snippets screenshot 3
assembly-300-snippets screenshot 4

Assembly 300 Snippets

Current Repository Progress:

  • Snippets: 210/300
  • Cheatsheets: 210/300
  • Samples: 210/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)

#NameDescriptionSnippetCheatsheetSample
1Hello WorldPrint "Hello, World!" to console using syscall.
2Move RegisterMove data between registers using mov.
3Add NumbersAdd two numbers using add.
4Subtract NumbersSubtract two numbers using sub.
5Multiply NumbersMultiply two numbers using imul.
6Divide NumbersDivide two numbers using idiv.
7Compare NumbersCompare numbers using cmp.
8Conditional JumpUse je for conditional branching.
9Simple LoopImplement a loop using jmp.
10Push Pop StackPush and pop data on the stack.
11Exit ProgramExit with a status code using syscall.
12Define VariableDefine a variable in .data section.
13Print StringPrint a string using write syscall.
14Read InputRead user input from stdin.
15Bitwise ANDPerform bitwise AND operation.
16Bitwise ORPerform bitwise OR operation.
17Bitwise XORPerform bitwise XOR operation.
18Shift LeftShift bits left using shl.
19Shift RightShift bits right using shr.
20Direct AddressingAccess memory using direct addressing.
21Indirect AddressingAccess memory using indirect addressing.
22Indexed AddressingAccess array elements with indexing.
23Increment RegisterIncrement a register using inc.
24Decrement RegisterDecrement a register using dec.
25Zero RegisterZero a register using xor.
26Flags RegisterCheck flags after arithmetic operation.
27Jump Not EqualUse jne for conditional branching.
28Jump GreaterUse jg for conditional branching.
29Jump LessUse jl for conditional branching.
30Loop CounterLoop using loop instruction.
31Print IntegerConvert and print an integer to stdout.
32Read IntegerRead an integer from stdin.
33Define ByteDefine a byte variable in .data.
34Define WordDefine a word variable in .data.
35Define DoublewordDefine a doubleword in .data.
36Uninitialized VariableDefine variable in .bss section.
37Move ImmediateMove immediate value to register.
38Load Effective AddressUse lea for address calculation.
39Negate NumberNegate a number using neg.
40Logical NOTPerform logical NOT using not.
41Swap RegistersSwap two registers using xchg.
42Test InstructionUse test to check bits.
43Clear Carry FlagClear carry flag using clc.
44Set Carry FlagSet carry flag using stc.
45Check Zero FlagBranch based on zero flag.
46Signed MultiplySigned multiplication with imul.
47Unsigned DivideUnsigned division with div.
48Print NewlinePrint a newline character.
49Simple If ElseImplement if-else logic with jumps.
50Nested LoopImplement nested loops.
51Bitwise Rotate LeftRotate bits left using rol.
52Bitwise Rotate RightRotate bits right using ror.
53Print Hex NumberConvert and print number in hex.
54Read CharacterRead a single character from stdin.
55Stack AlignmentAlign stack to 16 bytes.
56Compare StringsCompare two strings using cmpsb.
57Move StringMove string using movsb.
58Clear RegisterClear register using mov.
59Check Sign FlagBranch based on sign flag.
60Basic Array SumSum elements of an array.
61Modulo OperationCompute modulus using div.
62Print BooleanPrint true/false based on condition.
63Basic Switch CaseImplement switch-case with jumps.
64Count BitsCount set bits in a number.
65Reverse BitsReverse bits in a register.
66Check ParityCheck parity using test.
67Simple MacroDefine a NASM macro for reuse.
68Print ArrayPrint elements of an array.
69Copy ArrayCopy array using loop.
70Find MaxFind maximum in array.
71Find MinFind minimum in array.
72Basic SortSimple bubble sort implementation.
73String LengthCalculate string length.
74Reverse StringReverse a string in place.
75Convert CaseConvert string case (upper/lower).
76Basic Stack FrameSet up a basic stack frame.
77Call SubroutineCall a subroutine with call.
78Return ValueReturn a value from subroutine.
79Local VariableDefine local variable on stack.
80Basic While LoopImplement a while loop.
81Print DecimalPrint number in decimal format.
82Read StringRead a string from stdin.
83Bitwise Shift VariableShift a variable’s bits.
84Check OverflowCheck overflow flag after addition.
85Simple Array InitInitialize an array with values.
86Basic PointerUse a pointer to access memory.
87Swap VariablesSwap two variables in memory.
88Basic ConstantDefine a constant using equ.
89Check Even OddCheck if a number is even or odd.
90Print ASCIIPrint ASCII character from code.
91Basic Input ValidationValidate numeric input.
92Simple CounterCount from 1 to N.
93Basic FactorialCompute factorial iteratively.
94Fibonacci SequenceGenerate Fibonacci numbers.
95Array ReverseReverse an array in place.
96String ConcatConcatenate two strings.
97Basic GCDCompute GCD of two numbers.
98Prime CheckCheck if a number is prime.
99Sum DigitsSum digits of a number.
100Basic Array AccessAccess array elements using indexed addressing.

Intermediate Snippets (101–200)

#NameDescriptionSnippetCheatsheetSample
101Function CallCreate and call a function with stack frame.
102Recursive FactorialCompute factorial recursively.
103Call C FunctionCall C’s printf from assembly.
104Floating Point AddAdd floating-point numbers using x87 FPU.
105SSE Vector AddPerform vector addition with SSE.
106String CopyCopy a string using movsb.
107Heap AllocationAllocate memory using mmap.
108File WriteWrite to a file using syscalls.
109Thread CreationCreate a thread using clone.
110Inline AssemblyEmbed assembly in C code.
111String CompareCompare strings using cmpsb.
112Array SortImplement quicksort for array.
113Matrix AdditionAdd two matrices.
114Floating Point MultiplyMultiply floats using x87 FPU.
115SSE Vector MultiplyMultiply vectors with SSE.
116Dynamic ArrayAllocate dynamic array on heap.
117File ReadRead from a file using syscalls.
118Function ParametersPass multiple parameters to function.
119Stack Frame CleanupClean up stack after function call.
120Loop UnrollingOptimize loop with unrolling.
121String TokenizeSplit string by delimiter.
122Struct AccessAccess fields in a C-style struct.
123Matrix MultiplyMultiply two matrices.
124Recursive FibonacciCompute Fibonacci recursively.
125Binary SearchImplement binary search on array.
126Linked List CreateCreate a linked list node.
127Linked List TraverseTraverse a linked list.
128File AppendAppend to a file using syscalls.
129Mutex LockUse mutex for thread synchronization.
130SSE Matrix AddAdd matrices using SSE instructions.
131String SearchSearch for substring in string.
132Memory CopyCopy memory block using rep movsb.
133Floating Point DivideDivide floats using x87 FPU.
134Dynamic Stack AllocAllocate dynamic space on stack.
135Function Return StructReturn a struct from function.
136Recursive GCDCompute GCD recursively.
137Heap FreeFree heap memory using munmap.
138Thread JoinJoin a thread using syscalls.
139Matrix DeterminantCompute matrix determinant.
140String ReplaceReplace characters in a string.
141Linked List InsertInsert node in linked list.
142Linked List DeleteDelete node from linked list.
143SSE Dot ProductCompute dot product using SSE.
144File SeekSeek to position in file.
145Macro FunctionDefine a macro for function-like behavior.
146Array FilterFilter array based on condition.
147String TrimTrim whitespace from string.
148Floating Point CompareCompare floats using x87 FPU.
149Recursive PowerCompute power recursively.
150Dynamic MatrixAllocate matrix on heap.
151Bit ManipulationAdvanced bit manipulation techniques.
152Array MapApply function to array elements.
153String FormatFormat string with placeholders.
154SSE Matrix MultiplyMultiply matrices using SSE.
155File CopyCopy contents of one file to another.
156Recursive SumSum array recursively.
157Thread PoolImplement a simple thread pool.
158Struct ArrayArray of structs in memory.
159String Parse IntParse string to integer.
160Matrix InverseCompute matrix inverse.
161Linked List ReverseReverse a linked list.
162SSE Vector NormalizeNormalize vector using SSE.
163File DeleteDelete a file using unlink.
164Recursive Binary SearchRecursive binary search on array.
165Macro LoopUse macro for loop generation.
166String SplitSplit string into array of strings.
167Floating Point PowerCompute power for floats.
168Heap ReallocReallocate heap memory.
169Thread SynchronizationSynchronize threads with spinlock.
170Matrix TransposeTranspose a matrix using loops.
171Linked List SortSort a linked list.
172SSE Cross ProductCompute cross product using SSE.
173File PermissionsChange file permissions using chmod.
174Recursive Merge SortImplement merge sort recursively.
175String To FloatParse string to floating-point number.
176Dynamic StructAllocate struct on heap.
177SSE Matrix InverseCompute matrix inverse using SSE.
178File LockLock a file using flock.
179Recursive Tree TraversalTraverse a binary tree recursively.
180String EncodeEncode string (e.g., Base64).
181Linked List MergeMerge two linked lists.
182SSE Vector DistanceCompute vector distance using SSE.
183File RenameRename a file using rename.
184Recursive Quick SortImplement quicksort recursively.
185String DecodeDecode string (e.g., Base64).
186Dynamic Tree NodeAllocate binary tree node on heap.
187SSE Matrix DeterminantCompute determinant using SSE.
188File TruncateTruncate a file using truncate.
189Recursive Factorial TailTail-recursive factorial.
190String HashCompute hash of a string.
191Linked List CycleDetect cycle in linked list.
192SSE Matrix TransposeTranspose matrix using SSE.
193File StatsGet file stats using stat.
194Recursive Heap SortImplement heap sort recursively.
195String CompressCompress string using run-length encoding.
196Dynamic Hash TableImplement a hash table on heap.
197SSE Vector RotateRotate vector using SSE.
198File MonitorMonitor file changes using inotify.
199Recursive Tree SearchSearch binary tree recursively.
200Matrix TransposeTranspose a matrix using loops.

Advanced Snippets (201–300)

#NameDescriptionSnippetCheatsheetSample
201Simple BootloaderWrite a minimal bootloader.
202Kernel ModuleCreate a Linux kernel module.
203Interrupt HandlerSet up an interrupt handler.
204Memory AllocatorImplement a simple heap allocator.
205Port IORead/write to hardware ports.
206Disassemble BinaryDisassemble a binary with objdump.
207Self Modifying CodeWrite self-modifying code.
208AES EncryptionImplement AES encryption.
209Shellcode SpawnWrite shellcode to spawn a shell.
210Custom ISA EmulatorEmulate a toy instruction set.
211VGA GraphicsDraw pixels in VGA mode.
212Kernel SyscallImplement custom syscall in kernel.
213IDT SetupSet up Interrupt Descriptor Table.
214Page TableConfigure a page table.
215Device DriverWrite a simple device driver.
216Code ObfuscationObfuscate code with jump table.
217SHA HashImplement SHA-256 hash.
218Shellcode Reverse ShellShellcode for reverse shell.
219AVX Vector AddVector addition using AVX.
220Simple OS KernelMinimal OS kernel with boot.
221Memory ProtectionSet memory protection with mprotect.
222Keyboard InterruptHandle keyboard interrupt.
223Custom AllocatorAdvanced custom memory allocator.
224GPU ShaderWrite a simple GPU shader.
225Reverse Engineer LoopReverse engineer a loop construct.
226RSA EncryptionImplement RSA encryption.
227Shellcode InjectInject shellcode into process.
228AVX Matrix MultiplyMatrix multiply using AVX.
229Simple File SystemImplement a basic file system.
230Timer InterruptHandle timer interrupt.
231Memory Cache OptimizeOptimize code for cache efficiency.
232Network SocketCreate a TCP socket.
233Code PolymorphismWrite polymorphic code.
234SHA512 HashImplement SHA-512 hash.
235Shellcode Bind ShellShellcode for bind shell.
236AVX Vector NormalizeNormalize vector using AVX.
237Task SchedulerImplement a simple task scheduler.
238Page Fault HandlerHandle page faults in kernel.
239Memory CompressionCompress memory block.
240Network PacketCraft a network packet.
241Anti DebuggingImplement anti-debugging techniques.
242ECDSA SignatureImplement ECDSA signature.
243Shellcode StealthWrite stealthy shellcode.
244AVX Matrix InverseCompute matrix inverse using AVX.
245Process ForkFork a process using syscall.
246Exception HandlerHandle exceptions in kernel.
247Memory EncryptionEncrypt memory block.
248Network ServerImplement a simple TCP server.
249Code EncryptionEncrypt code section.
250AVX Dot ProductCompute dot product using AVX.
251Virtual MachineImplement a simple VM.
252Signal HandlerHandle signals using sigaction.
253Memory AlignmentAlign memory for performance.
254Network ClientImplement a TCP client.
255Code PackingPack code for size optimization.
256AVX Cross ProductCompute cross product using AVX.
257Process InjectionInject code into running process.
258Memory PagingImplement basic paging.
259Crypto HashImplement a custom crypto hash.
260Shellcode LoaderLoad and execute shellcode.
261Real Time InterruptHandle real-time interrupts.
262Memory DecompressionDecompress memory block.
263Network SnifferSniff network packets.
264Code Anti AnalysisAnti-analysis techniques for code.
265AVX Matrix DeterminantCompute determinant using AVX.
266Process MonitorMonitor process creation.
267Memory SnapshotTake snapshot of memory state.
268Network BroadcastSend broadcast packet.
269Code Self DecryptSelf-decrypting code.
270AVX Vector DistanceCompute vector distance using AVX.
271Thread SchedulerImplement thread scheduler.
272Memory VirtualizationVirtualize memory access.
273Crypto Stream CipherImplement stream cipher.
274Shellcode ObfuscationObfuscate shellcode.
275AVX Matrix TransposeTranspose matrix using AVX.
276Process Fork ExecFork and exec a process.
277Memory TracingTrace memory accesses.
278Network UDPImplement UDP communication.
279Code Anti TamperImplement anti-tamper mechanisms.
280AVX Vector RotateRotate vector using AVX.
281Kernel ThreadCreate kernel thread.
282Memory SandboxImplement memory sandbox.
283Crypto Block CipherImplement block cipher.
284Shellcode Anti DebugShellcode with anti-debugging.
285AVX Matrix SolveSolve matrix system using AVX.
286Process HookingHook a process function.
287Memory ForensicsAnalyze memory for forensics.
288Network FirewallImplement basic firewall rules.
289Code SigningImplement code signing.
290AVX Vector TransformTransform vector using AVX.
291Kernel DebugDebug kernel with breakpoints.
292Memory IsolationIsolate memory regions.
293Crypto Key ExchangeImplement key exchange.
294Shellcode PersistencePersistent shellcode execution.
295AVX Matrix EigenCompute eigenvalues using AVX.
296Process MigrationMigrate process to another CPU.
297Memory Encryption AESEncrypt memory with AES.
298Network ProtocolImplement custom protocol.
299Code VirtualizationVirtualize code execution.
300Shellcode ExecveShellcode to execute a program.
assembly-300-snippets

$ cat ./about.json

categoryEducational
licenseMIT License
createdMay 11, 2025
last_push6mo ago

$ echo $TOPICS

assemblyassembly-cheatsheetassembly-courseassembly-langassembly-languageassembly-language-programmingassembly-nasmassembly-snippetsassembly-x86-64nasmnasm-assemblernasm-assemblynasm-languagesnippets