x86-64

Why does the x86-64 System V calling convention pass args in registers instead of just the stack?

谁说胖子不能爱 提交于 2020-11-29 03:52:52
问题 Why is it that 32-bit C pushes all function arguments straight onto the stack while 64-bit C puts the first 6 arguments into registers and the rest on the stack? So the 32-bit stack would look like: ... arg2 arg1 return address old %rbp While the 64-bit stack would look like: ... arg8 arg7 return address old %rbp arg6 arg5 arg4 arg3 arg2 arg1 So why does 64-bit C do this? Isn't it much easier to just push everything to the stack instead of put the first 6 arguments in registers just to move

What's the best way to remember the x86-64 System V arg register order?

一世执手 提交于 2020-11-25 03:41:39
问题 I often forget the registers that I need to use for each argument in a syscall, and everytime I forget I just visit this question. The right order for integer/pointer args to x86_64 user-space function calls is: %rdi , %rsi , %rdx , %rcx , %r8 and %r9 . (with variadic functions taking AL = the number of FP args, up to 8) Or for system calls, %rax (syscall call number), and same args except %r10 instead of %rcx . What's the best way to remember these registers instead of google this question

Subtracting registers with an LEA instruction?

岁酱吖の 提交于 2020-11-25 02:22:44
问题 Does the LEA instruction support negative displacement? mov rax, 1 lea rsi, [rsp - rax] When I use the above code in my asm file I got the error: $ nasm -f macho64 test.asm $ error: invalid effective address I Know that we can do pointer arithmetic like this in C: void foo(char *a, size_t b) { *(a - b) = 1; } then I assume that: lea rsi, [rsp - rax] will work. And I also try to see what the GCC compiler do by using: $ gcc -S foo.c // foo.c has the function foo(above) in it but my asm

Subtracting registers with an LEA instruction?

老子叫甜甜 提交于 2020-11-25 02:22:26
问题 Does the LEA instruction support negative displacement? mov rax, 1 lea rsi, [rsp - rax] When I use the above code in my asm file I got the error: $ nasm -f macho64 test.asm $ error: invalid effective address I Know that we can do pointer arithmetic like this in C: void foo(char *a, size_t b) { *(a - b) = 1; } then I assume that: lea rsi, [rsp - rax] will work. And I also try to see what the GCC compiler do by using: $ gcc -S foo.c // foo.c has the function foo(above) in it but my asm

Subtracting registers with an LEA instruction?

大城市里の小女人 提交于 2020-11-25 02:18:48
问题 Does the LEA instruction support negative displacement? mov rax, 1 lea rsi, [rsp - rax] When I use the above code in my asm file I got the error: $ nasm -f macho64 test.asm $ error: invalid effective address I Know that we can do pointer arithmetic like this in C: void foo(char *a, size_t b) { *(a - b) = 1; } then I assume that: lea rsi, [rsp - rax] will work. And I also try to see what the GCC compiler do by using: $ gcc -S foo.c // foo.c has the function foo(above) in it but my asm

Subtracting registers with an LEA instruction?

时间秒杀一切 提交于 2020-11-25 02:18:21
问题 Does the LEA instruction support negative displacement? mov rax, 1 lea rsi, [rsp - rax] When I use the above code in my asm file I got the error: $ nasm -f macho64 test.asm $ error: invalid effective address I Know that we can do pointer arithmetic like this in C: void foo(char *a, size_t b) { *(a - b) = 1; } then I assume that: lea rsi, [rsp - rax] will work. And I also try to see what the GCC compiler do by using: $ gcc -S foo.c // foo.c has the function foo(above) in it but my asm