Learn coding with amol
Hello my name is amol sharma or vineet and this is my 9th part of learn coding with amol and in this part we are going to learn assembly.
ASSEMBLY PART - 9
Complete Assembly Programming Guide
Assembly language is a low-level programming language that is closely related to machine code. It is used to write programs that directly interact with the hardware. This guide will take you from beginner to advanced level.
1. Basics of Assembly Language
Assembly language uses mnemonics to represent machine instructions. Each processor architecture (like x86, ARM) has its own instruction set.
- Registers: Small storage locations in CPU (e.g., AX, BX, CX, DX in x86).
- Memory: Used to store data, accessed via addresses.
- Instructions: Commands like MOV, ADD, SUB, JMP.
- Comments: Denoted by
;in x86.
2. Basic Structure of an x86 Program
; This is a simple program in x86 assembly
section .data ; Data section
msg db 'Hello, World!',0
section .text ; Code section
global _start
_start:
; write syscall
mov edx,13 ; message length
mov ecx,msg ; message to write
mov ebx,1 ; file descriptor (stdout)
mov eax,4 ; syscall number (sys_write)
int 0x80 ; call kernel
; exit syscall
mov eax,1 ; syscall number (sys_exit)
int 0x80 ; call kernel
3. Common x86 Instructions
MOV- Moves data between registers or memoryADD- Adds valuesSUB- Subtracts valuesINC/DEC- Increment/DecrementPUSH/POP- Stack operationsCMP- Compare valuesJMP,JE,JNE- Jump instructionsINT- Software interrupt
4. Data Types
db- Define bytedw- Define word (2 bytes)dd- Define double word (4 bytes)dq- Define quad word (8 bytes)
5. Loops and Conditions
section .text
global _start
_start:
mov ecx,5 ; counter
loop_start:
; do something
dec ecx
jnz loop_start ; jump if not zero
mov eax,1 ; exit syscall
int 0x80
6. Procedures / Functions
section .text
global _start
print_hello:
; print "Hello"
ret ; return to caller
_start:
call print_hello ; call function
mov eax,1
int 0x80
7. Input / Output (Syscalls)
On Linux x86, syscalls are used for input/output:
sys_write- Write to stdout (eax=4)sys_read- Read from stdin (eax=3)sys_exit- Exit program (eax=1)
8. Advanced Topics
- Interrupts and Exception Handling
- Bit Manipulation (AND, OR, XOR, SHL, SHR)
- Stack and Memory Management
- Calling Conventions (cdecl, stdcall)
- Optimization Techniques
9. Recommended Tools
- Assembler: NASM, MASM
- Debugger: GDB, OllyDbg
- IDE: Visual Studio, VS Code
10. Practice Programs
; Program to add two numbers
section .data
num1 db 5
num2 db 10
sum db 0
section .text
global _start
_start:
mov al,[num1]
add al,[num2]
mov [sum],al
mov eax,1
int 0x80
With this guide, you now have a complete start-to-advanced overview of Assembly programming for x86. Practice is key to mastering it!

Comments
Post a Comment