Learn ASSEMBLY with Real Code Examples
Updated Nov 19, 2025
Code Sample Descriptions
1
Assembly Counter Simulation
section .data
count db 0
section .text
global _start
_start:
; increment count
inc byte [count]
; print count (pseudo code, actual printing requires syscalls)
; toggle theme (simulated with a variable, 0=Light, 1=Dark)
mov al, 0 ; isDark = 0
; increment, decrement, reset would be additional inc/dec/mov instructions
; exit program
mov eax, 60 ; syscall: exit
xor edi, edi ; status 0
syscall
Demonstrates a simple counter simulation using Assembly instructions for x86 architecture (console-based).
2
Assembly Simple Addition
section .data
a db 5
b db 3
result db 0
section .text
global _start
_start:
mov al, [a]
add al, [b]
mov [result], al
; exit
mov eax, 60
xor edi, edi
syscall
Adds two numbers using registers and stores result.
3
Assembly Factorial (Byte)
section .data
n db 5
fact db 1
section .text
global _start
_start:
mov al, [n]
mov bl, 1
factorial_loop:
mul bl
dec al
cmp al, 1
jg factorial_loop
mov [fact], al
; exit
mov eax, 60
xor edi, edi
syscall
Calculates factorial of 5 using loop and register.
4
Assembly Fibonacci Sequence
section .text
global _start
_start:
mov al, 0 ; fib0
mov bl, 1 ; fib1
mov cl, 0 ; counter
fibonacci_loop:
; compute next
mov dl, al
add dl, bl
; update registers
mov al, bl
mov bl, dl
inc cl
cmp cl, 5
jl fibonacci_loop
; exit
mov eax, 60
xor edi, edi
syscall
Generates first 5 Fibonacci numbers in registers (pseudo print).
5
Assembly Loop Counting
section .bss
counter resb 1
section .text
global _start
_start:
mov byte [counter], 1
count_loop:
; pseudo print counter
inc byte [counter]
cmp byte [counter], 11
jl count_loop
mov eax, 60
xor edi, edi
syscall
Counts from 1 to 10 using a loop.
6
Assembly Conditional Increment
section .data
counter db 3
section .text
global _start
_start:
mov al, [counter]
cmp al, 5
jge skip_increment
inc byte [counter]
skip_increment:
mov eax, 60
xor edi, edi
syscall
Increment counter only if below 5.
7
Assembly Swap Registers
section .text
global _start
_start:
mov al, 5
mov bl, 10
xchg al, bl
mov eax, 60
xor edi, edi
syscall
Swaps two values in registers.
8
Assembly Bit Toggle
section .data
flags db 0b00000001
section .text
global _start
_start:
xor byte [flags], 1
mov eax, 60
xor edi, edi
syscall
Toggles the least significant bit of a byte.
9
Assembly Array Sum
section .data
arr db 1,2,3,4,5
sum db 0
section .text
global _start
_start:
mov al, 0
mov ecx, 0
sum_loop:
add al, [arr+ecx]
inc ecx
cmp ecx, 5
jl sum_loop
mov [sum], al
mov eax, 60
xor edi, edi
syscall
Sum elements of a small byte array.
10
Assembly Compare Values
section .data
a db 5
b db 7
result db 0
section .text
global _start
_start:
mov al, [a]
cmp al, [b]
jl set_flag
jmp end
set_flag:
mov byte [result], 1
end:
mov eax, 60
xor edi, edi
syscall
Compare two bytes and set a flag.