Using nasm assembler
Run a project
nasm -felf64 filename.asm -o outfilename.asm
ld -o filename filename.o
chmod u+x filename
Notes
Assembly language consists of commands, which are directly mapped into machine code
8 - General purpose register
name => alias
- r0 => rax
- r1 => rcx
- r2 => rdx
- r3 => rbx
- r4 => rsp
- r5 => rpb
- r6 => rsi
- r7 -> rdi
Other registers
rip => stores address of next instruction to be executed
-
The operand is a constant value embedded in the instruction. Example: mov rax, 42
-
The operand is stored in a register.
Example: mov rbx, rax
-
The instruction contains the memory address of the operand. Example: mov rax, [0x1000]
-
A register contains the memory address of the operand. Example: mov rax, [rbx]
-
Combines a base register with a constant offset. Example: mov rax, [rbx + 8]
-
Uses a base register, an index register, and a constant offset. Example: mov rax, [rbx + rcx*4 + 8]
-
Address is specified relative to the current instruction pointer. Example: mov rax, [rip + label]
-
A complex form that can include scaling of an index register. Example: mov rax, [rsi + rdi*8]
-
Implicit addressing using stack pointer (RSP) for push/pop operations. Example: push rax or pop rbx
- lea reg, [address] => allows you to calclulate an address of a memory cell and store it somewhere
- call => used to perform function calls