Giter VIP home page Giter VIP logo

asm-x86's Introduction

Assembly x86 / x86_64

My learning of x86 / x86_64 assembly language.

GDB

# we use intel syntax
set disassemly-flavor intel

# show debug window with asm code
layout asm

# first we need to setup a break on main()
break _start

run # run the program 
ni # jump to next instruction
info registers # print registers content
print/x $eax # print value of specific register
print/d $eax # print value of specific register (as int)

General syntax

Data:

section .data
; db is 1 byte
name db "string"
name db 0xff
name db 100

; dw is 2 bytes
name dw 0x1234
name dw 1000

; dd is 4 bytes 
name dd 0x12341245
name dd 10000

Instructions:

section .text

mov   eax, 3      ; Move            - move to R/M value from L/M/R
xchg  eax, ebx    ; Swap            - swaps 2 values (R/M)

inc eax           ; Increment       - adds 1
dec eax           ; Decriment       - substractcs 1
add eax, ebx      ; Add             - add two values and stores a result in the first one
sub eax, ebx      ; Sub             - sub two values and stotes a result in the first one
neg eax           ; Negative        - converts value to negative

push 1234         ; Push to stack   - push value to the stack (R/M/L)
pop eax           ; Pop from stack  - pop value from the stack (R/M)
sub esp, 4        ; Stack malloc    - allocate some amount of bytes on the stack

call label        ; Function call   - pushes RIP to stack and performs a jump
ret               ; Return          - pops RIP from stack and performs a jump

pop eax           ; Same as return
jmp eax           ;

sub esp, 4        ; Same as push eax
mov [esp], eax    ;

Registers

Registers:

  • ESP - stack pointer
  • EIP - instruction pointer
  • ESB - base pointer (in order to call functions)

System calls

; system calls are defined in /usr/include/asm/unistd_64.h

mov rax, 0    ; read()
mov rax, 1    ; write()
mov rax, 60   ; exit()

syscall       ; make system call
Register Arguments
rdi 1st argument
rsi 2nd argument
rdx 3rd argument
rcx 4th argument
r8 5th argument
r9 6th argument

Branches

je  A, B ; if A == B
jne A, B ; if A != B (jnz - also)
jg  A, B ; if A > B
jge A, B ; if A >= B
jl  A, B ; if A < B
jle A, B ; if A <= B

; bitwise AND operation
test edx, 00800000h ; bit 23
; if we got value that is not != 0
jnz HasMMX

asm-x86's People

Contributors

vadimgush avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.