From f100c977800eb737481635de4cd5f14e7bc19fab Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sun, 15 Sep 2024 09:31:28 +0200 Subject: Added additional content to C and Asm interop --- ...2024-06-17-calling-assembly-functions-from-c.md | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'content') 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() { Now lets compile and link into final program with `tcc main.c sum.o -o main`. +Use this table to see what each register is being used for. + +| Register | Conventional use | Low 32-bits | Low 16-bits | Low 8-bits | +|----------|---------------------------------|-------------|-------------|------------| +| %rax | Return value, caller-saved | %eax | %ax | %al | +| %rdi | 1st argument, caller-saved | %edi | %di | %dil | +| %rsi | 2nd argument, caller-saved | %esi | %si | %sil | +| %rdx | 3rd argument, caller-saved | %edx | %dx | %dl | +| %rcx | 4th argument, caller-saved | %ecx | %cx | %cl | +| %r8 | 5th argument, caller-saved | %r8d | %r8w | %r8b | +| %r9 | 6th argument, caller-saved | %r9d | %r9w | %r9b | +| %r10 | Scratch/temporary, caller-saved | %r10d | %r10w | %r10b | +| %r11 | Scratch/temporary, caller-saved | %r11d | %r11w | %r11b | +| %rsp | Stack pointer, callee-saved | %esp | %sp | %spl | +| %rbx | Local variable, callee-saved | %ebx | %bx | %bl | +| %rbp | Local variable, callee-saved | %ebp | %bp | %bpl | +| %r12 | Local variable, callee-saved | %r12d | %r12w | %r12b | +| %r13 | Local variable, callee-saved | %r13d | %r13w | %r13b | +| %r14 | Local variable, callee-saved | %r14d | %r14w | %r14b | +| %r15 | Local variable, callee-saved | %r15d | %r15w | %r15b | +| %rip | Instruction pointer | | | | +| %rflags | Status/condition code bits | | | | + +You can read more about [x86-64 Machine-Level Programming](/assets/notes/asm64-handout.pdf). + -- cgit v1.2.3