Intel to AT&T Assembly

This is a discussion on Intel to AT&T Assembly within the Linux Programming forums, part of the Platform Specific Boards category; Hello, The following code was posted by Fordy in response to a question I had about the different calling conventions ...

  1. #1
    Registered User deoren's Avatar
    Join Date
    Mar 2003
    Posts
    63

    Post Intel to AT&T Assembly

    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;
    }
    Last edited by deoren; 03-16-2003 at 05:02 PM.

  2. #2
    Registered User deoren's Avatar
    Join Date
    Mar 2003
    Posts
    63

    Unhappy undefined reference

    Still no go...

    Code:
    static const char* szBuff __asm__( "szBuff" ) = "Hello World";
    worked great for getting rid of
    undefined reference to 'szBuff'
    but I'm still getting the errors mentioned about hello1 and hello2. I even used

    Code:
     extern "C" void Hello1 (const char* szBuff)
    and
    Code:
     extern "C" void Hello2 (const char* szBuff)
    to declare the functions. Still didn't work.

    So I put the __stdcall back in Hello2 so the code would work once we get the "undefined reference" to go away, so now Hello2 looks like
    Code:
     extern "C" void __stdcall Hello2(const char* szBuff)
    Oh, it's being compiled using g++, and here is the output:

    Executing g++.exe...
    g++.exe "D:\My Documents\code\test\calling_conventions\devcpp\cal ling.cpp" -o "D:\My Documents\code\test\calling_conventions\devcpp\cal ling.exe" -ansi -fverbose-asm -O3 -I"D:\DEV-CPP5B\include\c++" -I"D:\DEV-CPP5B\include" -L"D:\DEV-CPP5B\lib"
    C:\WINDOWS\TEMP\ccdiyggb.o(.text+0x6a)://D/My Documents/code/test/calling_conventions/devcpp/calling.cpp: undefined reference to `Hello1'
    C:\WINDOWS\TEMP\ccdiyggb.o(.text+0x78)://D/My Documents/code/test/calling_conventions/devcpp/calling.cpp: undefined reference to `Hello2'

    Execution terminated
    I included that to show that g++ is being invoked, and not gcc.

    I appreciate the help! At least I'm a step closer!
    Last edited by deoren; 03-16-2003 at 07:40 AM.

  3. #3
    Registered User deoren's Avatar
    Join Date
    Mar 2003
    Posts
    63

    Well... Zipslack likes it...

    That's odd. I tried it on several versions of g++ for Win32 : mingw.

    I tried using 3.2, 2.95.3-6, & 2.95.2. All of them report:
    undefined reference to `Hello1'
    undefined reference to `Hello2'
    I then rebooted and went into Zipslack 3.9 (www.slackware.com) and used g++ 2.7.2.3.

    It works fine there. I guess it has to do with the port from Linux to Win32. I wouldn't think something like that would cause a problem... kinda' seems to simple compared to some monstrous programs I've seen... but who knows.

    I'll have to look more into that. At least now I know that it's properly converted from Intel Assembly format to AT&T format.

    * Edited: It's in the proper format, but the functions would not be called using explicit calling conventions. Those have been added to the code, and do not affect GCC's ability to compile it under a Linux environment. However, nothing has changed with the way mingw looks at it. It has also been reported that cygwin has the same problems. Perhaps gcc is just more lax? I started a new thread "Can anyone using mingw compile this" to address this problem. Thanks!

    Thanks for your help vVv!
    Last edited by deoren; 03-16-2003 at 09:50 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Intel syntax on MinGW ?
    By TmX in forum Tech Board
    Replies: 2
    Last Post: 01-06-2007, 08:44 AM
  2. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 01:11 PM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 03:28 AM
  4. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 02:35 AM
  5. DJGPP assembly syntax ills...
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-11-2001, 01:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21