Hello,
The following code was posted by Fordy in response to a question I had about the different calling conventions used, Thread Title: "Please point out the obvious"
He's using inline assembly statements in the Intel syntax. Can anyone show me what the AT&T syntax would look like? The first code block is the working code that Fordy posted. The 2nd section is what I tried to modify, but unfortunately I get
undefined reference to `szBuff'
undefined reference to `Hello1'
undefined reference to `szBuff'
undefined reference to `Hello2'
I'm using DevCPP beta 5 which uses the mingw port of GCC,
2.95-3.6 which uses the AT&T syntax. Any help is appreciated.
Code:
#include <iostream>
void _cdecl Hello1(const char* szBuff)
//force C calling convention
{
std::cout << szBuff << std::endl;
}
void _stdcall Hello2(const char* szBuff)
//force STDCALL calling convention
{
std::cout << szBuff << std::endl;
}
int main()
{
const char* szBuff = "Hello World";
__asm
{
push szBuff //push the param onto the stack
call Hello1 //call the function
add esp,4 //restore the stack to previous state
push szBuff //push the param onto the stack
call Hello2 //call the function
//dont restore stack as Hello2 will do that
}
return 0;
}
And here is the unworking copy that was translated to AT&T syntax (I tried anyway)
Code:
// This code isn't finished. GCC uses AT&T syntax, which I'm not
// familiar with. Op top of that, I'm not really familiar with
// Assembly anyway!
#include <iostream>
void __cdecl Hello1(const char* szBuff)
//force C calling convention
{
std::cout << szBuff << std::endl;
}
void __stdcall Hello2(const char* szBuff)
//force STDCALL calling convention
{
std::cout << szBuff << std::endl;
}
int main()
{
const char* szBuff = "Hello World$";
asm
("
pushl szBuff; // ;push the param onto the stack
call Hello1; // ;call the function
addl $4, %esp; // ;restore the stack to previous state
pushl szBuff; // ;push the param onto the stack
call Hello2; // ;call the function
// ;dont restore stack as Hello2 will do that
");
return 0;
}