Results 1 to 16 of 16

Thread: How to use __asm__ in fc6 g++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Lightbulb How to use __asm__ in fc6 g++

    Dear All,
    Qt Code:
    1. #include <iostream>
    2. using namespace std;
    3. int main()
    4. {
    5. __asm__ int 5; // generate intertupt 5
    6. return 0;
    7. }
    To copy to clipboard, switch view to plain text mode 
    I have comiled this a.cpp file as follows;
    g++ a.cpp
    a.cpp: In function ‘int main()’:
    a.cpp:5: error: expected `(' before ‘int’
    a.cpp:5: error: expected unqualified-id before numeric constant
    and found the above error
    Can any one guide me where I am wrong;
    How a way I use interrupts using __asm__ in g++.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use __asm__ in fc6 g++

    Try embedding the assembly code in braces.

  3. #3
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to use __asm__ in fc6 g++

    Quote Originally Posted by wysota View Post
    Try embedding the assembly code in braces.
    I have spoil whole day for that but nothing get. Is anyone have a link or code for g++4.0.1 compiler.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use __asm__ in fc6 g++

    Try round brackets instead of braces as the compiler suggests.

  5. #5
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to use __asm__ in fc6 g++

    Quote Originally Posted by wysota View Post
    Try round brackets instead of braces as the compiler suggests.
    Qt Code:
    1. #include <iostream>
    2. using namespace std;
    3. int main()
    4. {
    5. char * am="int 5";
    6. (__asm__ int 5); // generate intertupt 5
    7.  
    8. return 0;
    9. }
    To copy to clipboard, switch view to plain text mode 
    and getting
    g++ a.c
    a.c: In function ‘int main()’:
    a.c:6: error: expected primary-expression before ‘asm’
    a.c:6: error: expected `)' before ‘asm’
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use __asm__ in fc6 g++

    I meant:

    Qt Code:
    1. __asm__ ( int 5 );
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. __asm__ { int 5 };
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to use __asm__ in fc6 g++

    Quote Originally Posted by wysota View Post
    I meant:

    Qt Code:
    1. __asm__ ( int 5 );
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. __asm__ { int 5 };
    To copy to clipboard, switch view to plain text mode 
    getting the following error respectively
    __asm__ ( int 5 );
    g++ a.c
    a.c: In function ‘int main()’:
    a.c:7: error: expected string-literal before ‘int’
    __asm__ { int 5 };
    g++ a.c
    a.c: In function ‘int main()’:
    a.c:7: error: expected `(' before ‘{’ token
    a.c:7: error: expected unqualified-id before numeric constant
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use __asm__ in fc6 g++

    How about this:
    Qt Code:
    1. asm("int 5");
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to use __asm__ in fc6 g++

    Quote Originally Posted by wysota View Post
    How about this:
    Qt Code:
    1. asm("int 5");
    To copy to clipboard, switch view to plain text mode 
    g++ a.c
    /tmp/cc8Vc1Ze.s: Assembler messages:
    /tmp/cc8Vc1Ze.s:23: Error: suffix or operands invalid for `int'
    getting the above error....
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use __asm__ in fc6 g++

    This is an assembler error, your assembly code is invalid.

  11. #11
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to use __asm__ in fc6 g++

    Quote Originally Posted by wysota View Post
    This is an assembler error, your assembly code is invalid.
    Probably, you are saying right!
    This is one of my program which is runned successfully;
    Qt Code:
    1. #include <iostream>
    2. using namespace std;
    3. int a, b;
    4.  
    5. void f1(void)
    6. {
    7. a = 5;
    8. b = 30;
    9.  
    10. asm
    11. (
    12. /*"movl $12, %ebx;"
    13.   "movl %ebx, a;"
    14.   "movl %ebx, b;"*/
    15. "movl %eax, a;"
    16. );
    17.  
    18. // cout<<"";
    19.  
    20. std::cout<<a<<std::endl;
    21. std::cout<<b<<std::endl;
    22. }
    23.  
    24. int main(){f1();}
    To copy to clipboard, switch view to plain text mode 
    Thanks for your help & quick response.
    But How a way I generate a interrupt no. 5 for print screen which doesn't take any input.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  12. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to use __asm__ in fc6 g++

    Here's an example from qatomic_i386.h:
    Qt Code:
    1. inline int q_atomic_fetch_and_add_int(volatile int *ptr, int value)
    2. {
    3. asm volatile("lock\n"
    4. "xaddl %0,%1"
    5. : "=r" (value), "+m" (*ptr)
    6. : "0" (value)
    7. : "memory");
    8. return value;
    9. }
    To copy to clipboard, switch view to plain text mode 
    Searching Google for example "g++ inline asm" would have surely been also productive.
    J-P Nurmi

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.