diff options
Diffstat (limited to 'content/notes')
| -rw-r--r-- | content/notes/2024-06-17-calling-assembly-functions-from-c.md | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/content/notes/2024-06-17-calling-assembly-functions-from-c.md b/content/notes/2024-06-17-calling-assembly-functions-from-c.md index 7e8683d..4887fb8 100644 --- a/content/notes/2024-06-17-calling-assembly-functions-from-c.md +++ b/content/notes/2024-06-17-calling-assembly-functions-from-c.md | |||
| @@ -47,3 +47,28 @@ int main() { | |||
| 47 | 47 | ||
| 48 | Now lets compile and link into final program with `tcc main.c sum.o -o main`. | 48 | Now lets compile and link into final program with `tcc main.c sum.o -o main`. |
| 49 | 49 | ||
| 50 | Use this table to see what each register is being used for. | ||
| 51 | |||
| 52 | | Register | Conventional use | Low 32-bits | Low 16-bits | Low 8-bits | | ||
| 53 | |----------|---------------------------------|-------------|-------------|------------| | ||
| 54 | | %rax | Return value, caller-saved | %eax | %ax | %al | | ||
| 55 | | %rdi | 1st argument, caller-saved | %edi | %di | %dil | | ||
| 56 | | %rsi | 2nd argument, caller-saved | %esi | %si | %sil | | ||
| 57 | | %rdx | 3rd argument, caller-saved | %edx | %dx | %dl | | ||
| 58 | | %rcx | 4th argument, caller-saved | %ecx | %cx | %cl | | ||
| 59 | | %r8 | 5th argument, caller-saved | %r8d | %r8w | %r8b | | ||
| 60 | | %r9 | 6th argument, caller-saved | %r9d | %r9w | %r9b | | ||
| 61 | | %r10 | Scratch/temporary, caller-saved | %r10d | %r10w | %r10b | | ||
| 62 | | %r11 | Scratch/temporary, caller-saved | %r11d | %r11w | %r11b | | ||
| 63 | | %rsp | Stack pointer, callee-saved | %esp | %sp | %spl | | ||
| 64 | | %rbx | Local variable, callee-saved | %ebx | %bx | %bl | | ||
| 65 | | %rbp | Local variable, callee-saved | %ebp | %bp | %bpl | | ||
| 66 | | %r12 | Local variable, callee-saved | %r12d | %r12w | %r12b | | ||
| 67 | | %r13 | Local variable, callee-saved | %r13d | %r13w | %r13b | | ||
| 68 | | %r14 | Local variable, callee-saved | %r14d | %r14w | %r14b | | ||
| 69 | | %r15 | Local variable, callee-saved | %r15d | %r15w | %r15b | | ||
| 70 | | %rip | Instruction pointer | | | | | ||
| 71 | | %rflags | Status/condition code bits | | | | | ||
| 72 | |||
| 73 | You can read more about [x86-64 Machine-Level Programming](/assets/notes/asm64-handout.pdf). | ||
| 74 | |||
