Questions tagged [calling-convention]
A calling convention refers to the way a function transmits parameters to a called function and receives a return value from it.
calling-convention
1,092
questions
3
votes
0
answers
51
views
How to pass arguments to a windows syscall in NASM assembly? [duplicate]
I am learning how to implement direct system calls using nasm assembly and c code, I have created a funcs.asm that contains
section .text
global NtOpenProcess
NtOpenProcess:
mov rax, 26h
...
0
votes
1
answer
36
views
x86 NASM Crash - Iterate over string
How to iterate over individual characters of a string in x86 assembly and print them?
global _main ; declare _main entry point
extern _printf ; extern method
section ....
-1
votes
0
answers
53
views
Why does gcc not allocate space for local variable in this example? [duplicate]
This is the C code I compiled with gcc -
#include <stdio.h>
#include <stdlib.h>
int sum(int arr[20]) {
int s = 0;
for (int i = 0; i < 20; i++)
s += arr[i];
return s;...
2
votes
2
answers
74
views
tail call optimization with arguments on stack and callee with more arguments than caller
I have been writing a compiler and have discussed this situation with a colleague.
In the most general case, suppose you have your arguments on the stack (once argument registers are exhausted).
If ...
0
votes
1
answer
88
views
Difference between calling convention and order of evaluation of function arguments in C? [duplicate]
The following code yields different outputs on different compilers;
#include <stdio.h>
void fun(int x, int y, int z) /* function definition */
{
printf("%d %d %d \n", x, y, z); /...
1
vote
0
answers
36
views
Stack alignment in cdecl
The x86 calling conventions page in wikipedia mentions the alignment of stack in cdecl calling convention:
Stack aligned on 16-byte boundary due to a bug.
What is that? a bug?
2
votes
1
answer
51
views
LDS is causing an infinite loop while LES is working perfectly
This is my only code code.asm. I am executing this function from a .c file. But with this simple code, using lds instead of les causes an infinite loop...
_COD SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:...
1
vote
0
answers
44
views
Change calling convention in compiler-explorer gcc x86-64
Out of curiosity, I wanted to understand the different calling conventions like cdecl or fastcall. So I look at the documentation from gcc and it seems we can use the cdecl or fastcall attributes in ...
6
votes
1
answer
241
views
Why does MSVC never return struct in RAX for member-functions?
I've stumbled across an oddity in MSVCs codegen, regarding structures that are used as return-values. Consider the following code (live demo here):
struct Result
{
uint64_t value;
};
Result ...
2
votes
2
answers
91
views
Ensuring x64 compliance of custom ASM-function in clang-cl
For my custom compiled native x64 JIT-code, I have certain instrinsic functions. A lot of them are just called from my code, thus I will generate with my own compiler. Some of them however are ...
3
votes
1
answer
189
views
Calling Rust functions from inline assembly and calling conventions
I'm working on some code that has be assembly within my Rust project. A coworker and I are discussing the calling conventions and I have been having trouble finding definitive resources for this.
As I ...
0
votes
1
answer
25
views
assembly code have a mistake Run-Time Check Failure
I have a Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function ...
2
votes
0
answers
136
views
Force GCC to return floats in integer registers
When targeting the x86(-32) architecture, GCC provides a way to completely disable generation of x87 FPU instructions and instead generate calls to library functions which do floating-point math in ...
1
vote
0
answers
49
views
Preventing Arm Neon d8-d15 spilling in a function
I'm having a function to be called through function pointer, which uses all the 32 Arm Neon registers.
The calling convention requires to spill and restore the bottom part of the registers d8-d15, ...
5
votes
1
answer
135
views
Type-traits for handling structs in Windows x64 calling convention
I'm trying to figure out how to detect if a certain c++-pass can be passed directly in a register, or whether an address has to be passed in the x64-calling convention.
For reference, I have my own ...