Assembly
A family of programming languages that provide instructions close to machine code.
Learn
Intro:
- https://shikaan.github.io/assembly/x86/guide/2024/09/08/x86-64-introduction-hello.html
- https://shikaan.github.io/assembly/x86/guide/2024/09/16/x86-64-conditionals.html
Notes
- In x86-64 there are 16 general-purpose registers, each 8 byte wide.
- You can access the whole register or only a part of it (1 byte, 2 bytes, 4 bytes).
rip
is the instruction pointer register.- File extensions:
.s
,.asm
. - File sections:
.data
(variables, optional),.rodata
(constants, optional),.text
(code, mandatory). - File syntax:
;
for comments,db
to declare strings,equ
to declare numbers. - Declare a label with
lbl:
, reference it withlbl
. - Control Transfer Instruction (CTI) types: unconditional (e.g.
jmp
) and conditional (e.g.je
,jg
,jl
). eflags
is a 32-bit register that stores various flags (e.g. zero flagZF
, sign flagSF
).
Instructions
mov r1, r2
: mover2
tor1
add r1, r2
:r1
+r2
, the result will be stored inrax
cmp r1, r2
:r1
-r2
, the result will be stored inZF
,SF
flagsjmp lbl
: gotolbl
je lbl
: gotolbl
ifZF=1
jg lbl
: gotolbl
ifSF=0
jl lbl
: gotolbl
ifSF=1
syscall
: make a syscall with the identifier stored inrax