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.
981
questions
0
votes
2
answers
53
views
Why does GCC use additional registers for pushing values onto the stack? [duplicate]
This C code
void test_function(int a, int b, int c, int d) {}
int main() {
test_function(1, 2, 3, 4);
return 0;
}
gets compiled by GCC (no flags, version 12.1.1, target x86_64-redhat-linux) into
...
-1
votes
1
answer
32
views
JUnit testing, Calculator classes and Test [closed]
static int[] intArr = {3, 17, 4};
public int sumOfAnArray(int[] intArr) {
int sum = 0;
int i;
for(i = 0; i < intArr.length; i++) {
sum += intArr[i];
}
return sum;
}
@...
-1
votes
1
answer
108
views
Difference between amd64 and Intel x86-64 stack frame
I'm learn ATT asm, so I'm also reading Linux amd64 ABI, and I notice Computer Systems: A Programmer's Perspective (CSAPP) has the same content (stack frame layout). I found the stack frame layout is ...
0
votes
2
answers
44
views
How did my variable turn into a function?
Hello fellow S Overflowers. This question might seem dumb to some, but I cannot express how much asking these conceptual questions has helped me understand coding in general and for that I want to ...
-1
votes
1
answer
49
views
beginner_question = 'When do we add arguments to functions?'
I was recently practicing some Python and I came onto a roadblock where I couldn't make my agg() to work, I later found out that it was because I didn't have to call the functions.
My question here is:...
2
votes
1
answer
59
views
Why is GCC with __attribute__((__ms_abi__)) returning values differently than MSVC does?
x86 Function Attributes in the GCC documentation says this:
On 32-bit and 64-bit x86 targets, you can use an ABI attribute to indicate which calling convention should be used for a function. The ...
2
votes
1
answer
61
views
Specifying registers for function arguments?
Some compilers, says old gcc or egcs, apply ABI-breaking optimization for static functions within single file, like passing arguments or returning results with arbitrary registers.
Consider some ...
-2
votes
0
answers
21
views
How to integrate app to app calling feature in android?
I want to integrate App to app calling feature like whatsapp, IMO, Skype etc in My Android App.
0
votes
1
answer
100
views
GCC calling convention for x86_64 Linux systems
I have written a minimal function to test whether I can call/link C and x86_64 assembly code.
Here is my main.c
#include <stdio.h>
extern int test(int);
int main(int argc, char* argv[])
{
...
7
votes
0
answers
60
views
Returning two AVX/AVX2 __m256d types in C++ function calls via registers
I am new to programming with the AVX/AVX2 instructions and am trying to optimize the speed of my code. Following the older expectation that passing by reference is faster I wrote my code to do that ...
1
vote
2
answers
136
views
What calling convention does printf() in C use?
So I've been practicing to write simple subroutines in FASMW using the CDECL and STDCALL calling conventions and it got me wondering about what the printf function in C would be using.
Also, a ...
0
votes
0
answers
42
views
Is it not neccessary to push EAX in this code? [duplicate]
I am new to assembly, and when I studied on the internet, I found the following code, but I don't know why push eax is not written before mov eax, [ebp+8].
; char* removerng(char* s, char a, char b)
; ...
0
votes
1
answer
23
views
SaveAs .xlsx and then open the same saved file (Calling Macros from another saved workbook)
I have this code written to take save as file name from excel range and copy pivot ranges and paste in template workbook (with macro in it) and save file in New Folder.
Now I want to call macro from ...
0
votes
1
answer
69
views
Why does `printf` with `%hu%` takes 4 bytes from stack instead 2?
I am studying assembly basics and I use printf quite often (which I thought I know good enough from C/C++ experience). I came across weird thing with 2 bytes (16 bits) values:
In 32 bit mode, when ...
7
votes
1
answer
106
views
Why does printf still work with RAX lower than the number of FP args in XMM registers?
I am following the book "Beginning x64 Assembly Programming", in Linux 64 system. I am using NASM and gcc.
In the chapter about floating point operations the book specifies the below code ...
3
votes
1
answer
99
views
Get G++ to use a custom calling convention to pass larger structs in registers instead of memory?
Short question:
Are there compiler options or functions attributes available in g++ that force the compiler to pass members of structures through registers instead of the stack.
Long question:
In my ...
0
votes
1
answer
36
views
Opentalk(Vonage) API set callertune for detect phone call ringing
How to detect the time when a phone starts ringing for outgoing calls.I am developing an application in which i am trying to make a call programatically and when call is connected to internet like ...
0
votes
0
answers
39
views
VBA Call Multiple Macros from Command Button and change one macro in loop - EXPETED FUNCTION OR VARIABLE
Sub Save_All_Files()
Call Account_Name_And_Year_1
Call Data_2021_1
Call Account_Name_And_Year_1
Call Data_2022_1
With Account_Name_And_Year_1
rootAccount = ...
1
vote
1
answer
99
views
What if RISC-V function has too many arguments?
Register
ABI
Name
Description
Saver
x10–11
a0–1
Function
arguments/return values
Caller
x12–17
a2–7
Function
arguments
Caller
What if I have ten arguments, where is the place for values to be saved?...
0
votes
1
answer
17
views
Python functions calling functions inside functions
In Python, say I have the following code:
def func0():
print("This is func0")
def func1():
print("func1 calls func0")
func0()
def func2():
def func21():
...
3
votes
1
answer
100
views
What calling convention should I use to make things portable?
I am writing a C interface for CPU's cpuid instruction. I'm just doing this as kind of an exercise: I don't want to use compiler-depended headers such as cpuid.h for GCC or intrin.h for MSVC. Also, I'...
0
votes
0
answers
21
views
X86_64 call convention issue
As we know, X86_64 use register rdi, rsi, rdx, rcx, r8, r9 to store normal function's arguments, and use stack memory to store large argument, and use xmm to store float and double argument. But in my ...
1
vote
2
answers
115
views
What makes the calling convention different?
From my knowledge, the calling convention is depending on whether the platform is Windows or Linux.
I wanna know,
Compilers make the calling convention different.
Platforms make the calling ...
1
vote
0
answers
131
views
Implement cpuid instruction from assembly in C [closed]
I'm trying to implement a C interface for processor's cpuid instruction. I'm aware that there are plenty of libraries for this and that using inline assembly for compilers that support it would be ...
0
votes
1
answer
75
views
How passing parameters by ref works in assembly
I'm very very new to assembly so please bear with me.
I have this code that passes a value by reference to a function in order to modify it :
[MethodImpl(MethodImplOptions.NoOptimization | ...
6
votes
2
answers
265
views
Consequence of violating macOS's ARM64 calling convention
I'm porting some AArch64/ARM64/Apple Silicon assembly code from Linux to macOS.
This code uses all 31 available registers (stack pointer doesn't count) to avoid almost all cases of spilling; the Linux ...
4
votes
0
answers
87
views
What is the rationale for setting all SSE/AVX registers call-clobbered in the SysV ABI?
The SysV ABI for x86_64 sets all XMM0~XMM15 registers call-clobbered. Whenever you call a function during operating on a lot of SSE registers, hopefully it gets inlined, or otherwise the compiler will ...
1
vote
1
answer
44
views
Collatz conjecture function in Python3 calling itself when being assigned to a variable
I'm reading the book "Automate the boring stuff" by Al Sweigart to start learning Python (it is free online, so you can check it if you're interested, or you think that it would help solve ...
1
vote
1
answer
93
views
Why doesn't gcc zero the upper values of an XMM register when only using the lower value with SS/SD instructions?
For example with such function,
int fb(char a, char b, char c, char d) {
return (a + b) - (c + d);
}
gcc's assembly output is,
fb:
movsx esi, sil
movsx edi, dil
movsx ...
0
votes
1
answer
104
views
ARM calling convention for more than 4 params: conflicting information
I'm trying to understand the ARM calling convention on Linux, under gcc, especially with more than 4 params. Stackoverflow, Wikipedia, and ARM docs have information which is sometimes in conflict.
I ...
0
votes
0
answers
59
views
why call glibc function crash without xor %rax, %rax? [duplicate]
i call glibc function, for example, printf:
mov $some_string, %rdi
call printf //<----crash
in some cases, such a call will crash. I add xor %rax, %rax this solves the problem.
I have two ...
1
vote
1
answer
130
views
How do you allocate memory on the heap without using libc in linux [duplicate]
I'm trying to alocate memory on the heap without using libc and using linux system calls. I've tried using mmap and brk but brk doesn't return the end of heap like I've read it does for most systems, ...
0
votes
1
answer
60
views
why procedure need stack frame or shadow stack? [duplicate]
(Sorry for my bad english, because i am from South Korea)
i tried this code
lea rcx, QWORD PTR [message]
call [print_message] ;it covered return address to bad address
xor rcx, rcx
ret
and crashed......
0
votes
0
answers
51
views
Print array on asm... Why printf spoils the register? [duplicate]
i want to print dynamic array with printf... But after call printf i have some strange behavior(for me). Call printf changes unrelated register.
My questions:
In print_array gdb show that after ...
0
votes
1
answer
114
views
How does this assembly function return a value?
I have made a function in C which is pretty straightforward, it uses strlen() from <string.h> to return the length of a char* variable:
int length(char *str) {
return strlen(str);
}
Here ...
0
votes
2
answers
111
views
Clang doesn't pass value via register as the code specified
I have the below snippet of code, and here I want to pass the value of variable num by register rax, but it seems in the assembly code, clang doesn't use rax directly. Rather, it saves the value of ...
0
votes
1
answer
80
views
Understanding assembly instructions for a function summing three ints of an std::array
I have the following c++ function which simply sums the three elements of the given input array.
#include <array>
using namespace std;
int square(array<int, 3> ar) {
int res = 0;
...
0
votes
0
answers
70
views
Why does unoptimized compiler output sub/add RSP in some functions but not others?
With reference to the following code:
#include <cstdint>
void func() {
return;
}
void funcparent() {
uint64_t h = 99;
func();
}
void funcparent2() {
func();
}
void ...
1
vote
1
answer
128
views
in which registers are function parameters passed in cpp x86_64 arch (mac os ) [duplicate]
I am currently reading a book about assembly for x86_64 arch. I am using extern “c” so I am calling a assembly from cpp. The guy is coding in visual studio and he says that cpp is loading the ...
1
vote
2
answers
154
views
Calling a function in a loop of another function
Background - I have a function that takes an API response (api_response) from another function (api_response = api_call()). Code Block #1 continues to iterate until meta is in the response. Once meta ...
1
vote
1
answer
63
views
The algorithm for the generic va_arg(l, type) implementation
I am now looking into the implementation detail of the va_arg macro which is defined in the AMD64 ABI documentation, and what confuses me is the second step of the algorithm as I showed below. My ...
0
votes
0
answers
50
views
Can you determine the call convention of a compiled function?
From looking at an executable, is there generally any information in the executable file that relates to the calling convention of the functions inside it?
If so, could you provide an example for the ...
0
votes
0
answers
97
views
Is RSP always a multiple of 16 in GCC at the entry (first intruction) of a function (with default options)? [duplicate]
Due to the 16 bytes alignment by default, does this imply the assertion in my question ?
0
votes
0
answers
17
views
asm x86 64: Calling a varadic func from within another func [duplicate]
On x86 64 SysV (Linux), my understanding is that, assuming no floating point arguments, to call a varadic func like printf, we simply zero al and call the func normally:
mov al, 0
mov rdi, msg
call ...
0
votes
0
answers
115
views
The parameter passed to the function in ARM 32 bit assembly language
When calling a function void foo (int *x) { … } from ARM 32-bit assembly, the parameter passed to the function foo must be in r0, where r0 contains a signed integer or the address of an integer?
1
vote
1
answer
85
views
Why use vector registers instead of saving stdargs in stack?
So I was reading the SYSTEM V AMD64 ABI and there it was written that we have to use vector registers to save the stdargs and set AL to the number of registers that has been used to put the arguments.
...
0
votes
0
answers
14
views
What is the purpose of this extended prologue? [duplicate]
I understand the classic function prologue, push ebp mov ebp esp
But it seems new compilers have a more complicated prologue that adds 3 instructions and uses ecx.
My question : It seems the purpose ...
-1
votes
1
answer
22
views
printing the function is producing output but call it is not (python) [duplicate]
This function, when printed, outputs 7 but when called, does not output anything. Can someone please explain why this is happening?
`def myfunc(x, y):
return (x+y)
myfunc(3,4)
This does not output ...
0
votes
0
answers
67
views
Why parameters in stack isn't continuous
I'm trying to create an os for learning. To format string, I create sprintf like below:
void sprintf(char *buf, const char *format, ...) {
...
}
I don't use the __builtin_va_list but manually get ...