Show Menu

Linux Assembler Cheat Sheet by

Linux Assembler Basics
assembler     nasm

General Registers

EAX
Accumu­lator
EBX
Base
ECX
Counter
EDX
Data
General Registers: specific values are expected when calling the kernel.

Pointe­r-R­egi­sters

ESP
Stackp­ointer
EBP
Basepo­inter
EIP
Instru­cti­onp­ointer

Index-­Reg­isters

ESI
Source Index
EDI
Destin­ation Index

Segment- Registers

ECS
Code-S­egment
EDS
Data-S­egment
ESS
Stack-­Segment
EES
Extra-­Segment

Flags

NASM Basics

-f
filesystem
-g
debugg­infos
-o
output

Compiling a Code

nasm -f elf32 -g -o filename.o filename.nasm
ld -o filename filename.o
in 64bit Archit­ecture use -f elf64
 

Syscal­l-N­umbers Linux

EAX
Name­(EBX, ECX, EDX)
1
exit( int)
2
fork( pointer)
3
read( uint, char*, int)
4
write( uint, char*, int)
5
open( char *, int, int)

NASM Code-S­ections

.text
Code
.data
initia­lized Data
.bss
uninit­ialized Data

Example

global _start

.data
    msg db "Hello World",0xa
    len equ $-msg

.text

_start:
    mov eax, 0x4
    mov ebx, 0x1
    mov ecx, msg
    mov edx, len
    int 0x80

exit:
    mov eax, 0x1
    mov ebx, 0x1
    int 0x80

Misc

int Nr
call Interrup Nr
call label
jumps to label
ret
returns to call
nop
no operation
lea dest­,src
load effective addr. to dest
int 0x80 calls the Kernel in Linux

Logical Operations

neg op
two-Co­mpl­ement
not op
invert each bit
and dest­,s­ource
dest= dest source
or dest­,s­ource
dest­=dest source
xor dest, surce
dest = dest XOR source
 

Control / Jumps (signed Int)

cmp op1op2
Compare op1 with op2
test op1op2
bitwise comparison
jmp dest
uncond­itional Jump
je dest
Jump if equal
jne dest
Jump if not equal
jz dest
Jump if zero
jnz dest
Jump if not zero
jg dest
Jump if greater
jge dest
Jump if greater or equal
jl dest
Jump if less
jle dest
Jump if less or equal
For unsigned Integer use ja, jae (above) or jb, jbe (below)

Mnemonics Intel

mov dest, source
Moves Data
add dest, value
Add value to dest
sub dest­,v­alue
Subtract value3 from dest*
inc dest
Increment dest
dec dest
Decrement dest
mul src
Multiply EAX and src
imul dest, source
dest = dest * source
General Structure:
[label] mnemonic [operands] [;comment]

Stack Operations

push source
Insert Value onto the stack
pop dest
Remove value from stack
Stack is a LIFO-S­torage (Last In First Out)

Download the Linux Assembler Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/siniansung_linux-assembler.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          More Cheat Sheets by Siniansung