Thread: Gnu inline assembler question

  1. #1
    Registered User
    Join Date
    Jul 2015
    Posts
    17

    Gnu inline assembler question

    Greetings,

    I am currently trying to convert code from a old compiler to a new one. Specifically GNU Gcc/G++.

    Is it possible to return anything from a inline assembler call?

    for example:

    Code:
    #ifdef HEAP_DEBUG 
    			unsigned long int iTemp;
    
    
    			iTemp = asm(" move.l __HEAP,d0"); 
    			
    			iCurrentHeapSize = iTemp - iHeapBasePointer;
    
    
    			if(iCurrentHeapSize > iMaxHeapSize) { iMaxHeapSize =
    			iCurrentHeapSize; } 
    		#endif
    I keep getting a parse error while compiling and I am not sure why.

    Is the line of code in red the correct way to return values?
    (My assumption, I am not the original coder.)

    Thanks for your time.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Yes, of course, but you need a different syntax. For example,
    this piece of assembly:
    Code:
    MOV EAX, myVar
    MUL EAX
    MOV myVar, EAX
    would become:
    Code:
    asm("movl %0, %%eax \n\t"
        "mull %%eax \n\t"
        "movl %%eax, %0 \n\t"
        : "=m"(myVar)
        : : "%eax");
    It is a little bit difficult, here is what you need to know about gcc inline assembly:
    https://www.ibiblio.org/gferg/ldp/GC...bly-HOWTO.html

    The assembly seems so different because gcc uses AT&T syntax by default.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Jul 2015
    Posts
    17
    Hey GReaper,

    Thanks for your response.

    It never occured to me that I would not have the correct syntax.

    Thanks for your input.

  4. #4
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    830
    Regarding the Assembly itself, you can use Intel syntax with GCC if you specify it. This might be preferable if your old code base is written that way. I think it looks neater anyway.

  5. #5
    Registered User
    Join Date
    Jul 2015
    Posts
    17
    Adrian-

    I am using a specific version of the GNU compiler.

    https://www.ashware.com/gnu-power-ar...c-compiler.htm

    It is supposed to support the M68k chipset.

    I was wondering if you happened to know if i could choose an assembly option for that desired type.

    thanks for your time.

  6. #6
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    830
    Ah sorry, I had blindly assumed x86. You'll have to check if your version of GNU Assembler can work with the -masm=dialect flag. I hope it can.

    Edit: I haven't thought this through. I reckon with M68k there are probably not multiple choices. I don't know anything about it.
    Last edited by -Adrian; 07-14-2015 at 02:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc inline assembler - rounding mode
    By mrsirpoopsalot in forum C Programming
    Replies: 10
    Last Post: 02-08-2010, 07:27 PM
  2. inline assembler as alternative to int86()
    By Bigbio2002 in forum C Programming
    Replies: 3
    Last Post: 11-12-2004, 04:57 PM
  3. Inline Assembler Macros?
    By Aidman in forum C++ Programming
    Replies: 14
    Last Post: 07-15-2003, 05:10 AM
  4. Inline Assembler
    By mikef in forum C Programming
    Replies: 4
    Last Post: 08-22-2002, 03:28 PM
  5. Watcom C++ inline assembler
    By r0x in forum C++ Programming
    Replies: 0
    Last Post: 06-03-2002, 11:21 AM

Tags for this Thread