2023-11-30 09:44:31 +00:00
|
|
|
+++
|
|
|
|
title = "x86_64 Assembly notes"
|
|
|
|
date = 2023-11-30
|
|
|
|
draft = true
|
|
|
|
description = "Notes I gathered for myself as I learn."
|
|
|
|
[taxonomies]
|
|
|
|
categories = ["asm", "nasm", "x86_64"]
|
|
|
|
+++
|
|
|
|
|
|
|
|
Here is a post I will probably update as I learn more x86_64 assembly.
|
|
|
|
|
2023-11-30 10:13:11 +00:00
|
|
|
# AMD64 ABI Reference
|
|
|
|
|
|
|
|
From left to right, pass as many parameters as will fit in registers. The order in which registers are allocated, are:
|
|
|
|
|
|
|
|
- For non-floats: rdi, rsi, rdx, rcx, r8, r9.
|
|
|
|
- For floating-point: xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7.
|
|
|
|
- Callee saved: rsp, rbx, rbp, r12-r15
|
|
|
|
- Return value: `rax`
|
|
|
|
- Stack pointer: `rsp`
|
|
|
|
- Base pointer: `rbp`
|
|
|
|
|
|
|
|
# Call Frame
|
|
|
|
|
|
|
|
Stack grows downwards.
|
|
|
|
|
|
|
|
```asm
|
|
|
|
caller:
|
|
|
|
push rbp ; save old frame
|
|
|
|
mov rbp, rsp ; init frame
|
|
|
|
; arguments passed in the stack are upwards
|
|
|
|
mov r14, [rbp + 0x10]
|
|
|
|
; ...
|
|
|
|
mov rsp, rbp
|
|
|
|
pop rbp
|
|
|
|
ret
|
|
|
|
```
|
2023-11-30 09:44:31 +00:00
|
|
|
|
|
|
|
## x86_64 Cheatsheet
|
|
|
|
|
|
|
|
|s|b|
|
|
|
|
|---|---|
|
|
|
|
|a|b|
|
2023-11-30 10:13:11 +00:00
|
|
|
|a|b|
|
|
|
|
|a|b|
|
|
|
|
|a|b|
|