Thread: Inline assembly error

  1. #1
    Registered User TheEngineer's Avatar
    Join Date
    Aug 2009
    Posts
    50

    Inline assembly error

    I have the following snippet of inline assembly code in my ConstHeader.h file:
    Code:
    #define REG_AP(mr,reg_flag) \
      ({ \
    		reg_flag \
    		__asm__ ("pushl %0\n" :"=m"(*mr)); 
    		__asm__ ("call  0x8000\n"); 
    		}) /* FYI this is line 81 */
    When compiling, I get the following error:

    Code:
    ../ConstHeader.h:81: error: expected identifier or `(' before `}' token
    ../ConstHeader.h:81: error: expected identifier or `(' before `)' token
    I have tried lots of ways to fix it but cannot figure out why I am getting this error. Any ideas?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    a) how do you call the macro?
    b) which compiler?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by TheEngineer View Post
    I have the following snippet of inline assembly code in my ConstHeader.h file:
    Code:
    #define REG_AP(mr,reg_flag) \
      ({ \
    		reg_flag \
    		__asm__ ("pushl %0\n" :"=m"(*mr)); 
    		__asm__ ("call  0x8000\n"); 
    		}) /* FYI this is line 81 */
    When compiling, I get the following error:

    Code:
    ../ConstHeader.h:81: error: expected identifier or `(' before `}' token
    ../ConstHeader.h:81: error: expected identifier or `(' before `)' token
    I have tried lots of ways to fix it but cannot figure out why I am getting this error. Any ideas?
    Looks like you need a couple of more \ after __asm__ lines. . .

  4. #4
    Registered User TheEngineer's Avatar
    Join Date
    Aug 2009
    Posts
    50
    Quote Originally Posted by Salem View Post
    a) how do you call the macro?
    b) which compiler?
    a)It is called using the REG_AP() function in the main c file
    b) gcc

  5. #5
    Registered User TheEngineer's Avatar
    Join Date
    Aug 2009
    Posts
    50
    Quote Originally Posted by Kennedy View Post
    Looks like you need a couple of more \ after __asm__ lines. . .
    Like this?:
    Code:
    #define REG_AP(mr,reg_flag) \
      ({ \
    		reg_flag \
    		__asm__ ("pushl %0\n" :"=m"(*mr)); \  /*pushes null onto stack */
    		__asm__ ("call  0x8000\n"); \
    })
    I get the same error adding them in. Any other thoughts?

  6. #6
    Registered User
    Join Date
    Dec 2008
    Location
    Black River
    Posts
    128
    At first glance, it seems that you need to move the *mr parameter to act as input since it's obviously not an output parameter (ie: change the first assembly line to `"pushl %0" : : "m"(*mr)). Also, I remember that `push' didn't really need any suffix when it was called in C, but I could be wrong about that.

    Depending on what `reg_flag' is, you may also get errors there.
    Stick close to your desks and never program a thing,
    And you all may sit in the standards commitee!

  7. #7
    Registered User TheEngineer's Avatar
    Join Date
    Aug 2009
    Posts
    50
    Quote Originally Posted by Ronix View Post
    At first glance, it seems that you need to move the *mr parameter to act as input since it's obviously not an output parameter (ie: change the first assembly line to `"pushl %0" : : "m"(*mr)). Also, I remember that `push' didn't really need any suffix when it was called in C, but I could be wrong about that.

    Depending on what `reg_flag' is, you may also get errors there.
    Hmmm...doesn't seem to make a difference. I still keep getting the error about the line with "})"

    Also, I have several other commands like this in the file that do not cause errors. For instance, if I comment the posted commands out, I don't get any other similar errors

  8. #8
    Registered User
    Join Date
    Dec 2008
    Location
    Black River
    Posts
    128
    Can you post an example invoking the macro? I don't really know what you could be passing as reg_flag, but maybe the error lies there...
    Stick close to your desks and never program a thing,
    And you all may sit in the standards commitee!

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    > a)It is called using the REG_AP() function in the main c file
    Nice (and useless)

    As in
    REG_AP(Im_a_bananna);

    or
    REG_AP(eax)

    or
    ....



    > __asm__ ("pushl %0\n" :"=m"(*mr)); \ /*pushes null onto stack */
    The \ in macros MUST be the absolute last thing on a line to be treated as line folding.
    Put the comment before the \

    And yes, EVERY line of your multiline macro needs a \
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User TheEngineer's Avatar
    Join Date
    Aug 2009
    Posts
    50
    Quote Originally Posted by Salem View Post
    >
    > __asm__ ("pushl %0\n" :"=m"(*mr)); \ /*pushes null onto stack */
    The \ in macros MUST be the absolute last thing on a line to be treated as line folding.
    Put the comment before the \
    This was it, had to move the comment. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM