0
I am using the MASM syntax to make the codes below.
I tried with this function, for example:
__asm(
"soma:\n"
"push ebp\n"
"mov ebp, esp\n"
"mov eax, DWORD PTR[ebp+8]\n"
"mov edx, DWORD PTR[ebp+12]\n"
"add eax, edx\n"
"pop ebp\n"
"ret"
);
and made that call
int main(){
int result;
result = soma(10,7);
printf("%d",result);
}
In this case, the Assembly function was not set to C and then the call failed.
In the same way I tried to do it backwards:
int soma(int x,int y){
return (x+y);
}
With the following call
int main(){
int result; /*Colocado em ebp-12 neste caso particular */
__asm(
"push 7\n"
"push 10\n"
"call soma\n"
"add esp, 8\n"
"mov DWORD PTR[ebp-12],eax" /* coloca 17 no result */
);
printf("%d",result);
}
I analyzed the generated Assembly on the site godbolt and both codes generate the same Assembly but neither of the two works. However, if I use Assembly for the function and Assembly for the call it will work just as if I use C for the function and C for the call. I want to bring the two together somehow.
Both C code and Assembly code will work normally, but either of the two mixtures failed
The problem in both mixtures was Undefined Reference to`sum'
The code in Assembly will compile using the command below
gcc -m32 -masm=intel sum.c
This answers your question? How to run Assembly inline in a code with variables in C?
– pic
Update: half of the problem has been solved from your suggestion
– gabriel88766