This guide is part seven of the series, X86–64 Assembly Language Program.
This article is more of a reference guide for those learning x86–64 Assembly Language. I hope you find the information and links at the bottom helpful.
Registers
General-purpose registers — there are 16 general-purpose registers — rax
, rbx
, rcx
, rdx
, rbp
, rsp
, rsi
, rdi
, r8
, r9
, r10
, r11
, r12
, r13
, r14
, r15
data
- section is used for declaring initialized data or constantsbss
- section is used for declaring non initialized variablestext
- section is used for coderdi
- first argumentrsi
- second argumentrdx
- third argumentrcx
- fourth argumentr8
- fifth argumentr9
- sixth
The first six integer or pointer arguments are passed in registers rdi
, rsi
, rdx
, rcx
, r8
, r9
. r10
is used as a static chain pointer in the case of nested functions.
rax
is used as the return value from a function.
The registers rbx
, rbp
, and r12
– r15
are preserved registers.
All other registers must be saved by the caller if it wishes to preserve its values.
OPERATIONS
ADD
- integer addSUB
- subtractMUL
- unsigned multiplyIMUL
- signed multiplyDIV
- unsigned divideIDIV
- signed divideINC
- incrementDEC
- decrementNEG
- negate
The initial number must be stored in rax
. rax
can be multiplied by a value in any of the other registers. The result will be stored in rax
.
Control Flow
JE
- jump if equalJZ
- jump if zeroJNE
- jump if not equalJNZ
- jump if not zeroJG
- jump if the first operand is greater than secondJGE
- jump if the first operand is greater or equal to secondJA
- the same that JG, but performs an unsigned comparisonJAE
- the same that JGE, but performs an unsigned comparison
Date Types
The fundamental data types are bytes, words, doublewords, quadwords, and double quadwords.
byte
is eight bitsword
is two bytesdoubleword
is four bytesquadword
is eight bytesdouble quadword
is sixteen bytes (128 bits).
.DATA Directive
Directives are commands that are part of the assembler syntax but are not related to the x86 processor instruction set. All assembler directives begin with a period (.).
The .DATA
directive is used for setting values in memory.
Syntax
The syntax within the .DATA
directive is
variable name
define-directive
initial-value
There are five basic forms of the define directive −
+-----------+-------------------+-------------------+
| Directive | Purpose | Storage Space |
+-----------+-------------------+-------------------+
| DB | Define Byte | allocates 1 byte |
| DW | Define Word | allocates 2 bytes |
| DD | Define Doubleword | allocates 4 bytes |
| DQ | Define Quadword | allocates 8 bytes |
| DT | Define Ten Bytes | allocates 10 byte |
+-----------+-------------------+-------------------+
For example:
choice DB 'y'
number DW 12345
GDB
Display the value of ecx
register which is a char pointer (in other words, print the string referred to):
display (char *) $ecx
Note, this will display the value at every break of the program execution, including each step if you are stepping through. To stop this behavior:
undisplay 1
Note that the number can be two, three, or something else if there are multiple variables in display mode.
Further Resources
Tutorial Links
NASM
GDB
ASSEMBLY
- Say Hello to Assembly (Linux x64)
- Assembly — Basic Syntax
- x86–64 Assembly
- Intro to x64 by Intel
- Video Series on x86_64 Linux Assembly
Docker
Quick Reference Links
NASM
LD Linker
Assembly
- X86–64 Assembly Programming
- X86–64 w/ Ubuntu
- Intel® 64 and IA-32 Architectures Software Developer’s Manual Part 1, Part 2
- Calling Conventions
- Linux System Call Table
Call Stack
Utilities
Docker