Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Inline Assembler Macros?

Inline Assembler Macros?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++performancehelpquestion
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aidman
    wrote on last edited by
    #1

    Hi, all :) I am trying to write a high performance library by using inline assembler, but I have encountered a irritating problem. It seems that VC++ refuses to accept multi-instructions within the inline asm section for the macro. For example, I can write a inline assembler macro with the single instruction “mov eax, 0” but that’s it, VC++ refuses to accept anymore instructions. The following code might give a better understanding. #define TestMacro1(x) _asm{ mov eax, 0 } // This works #define TestMacro2(x) _asm{ mov eax, 0; mov ebx, 0 } // This doesn’t So what I am trying to do here is to add more then one instruction into the macro, but I don’t know how. Any ideas on how to solve this are highly appreciated. Thanks in advance. Aidman » over and out

    PJ ArendsP T T 3 Replies Last reply
    0
    • A Aidman

      Hi, all :) I am trying to write a high performance library by using inline assembler, but I have encountered a irritating problem. It seems that VC++ refuses to accept multi-instructions within the inline asm section for the macro. For example, I can write a inline assembler macro with the single instruction “mov eax, 0” but that’s it, VC++ refuses to accept anymore instructions. The following code might give a better understanding. #define TestMacro1(x) _asm{ mov eax, 0 } // This works #define TestMacro2(x) _asm{ mov eax, 0; mov ebx, 0 } // This doesn’t So what I am trying to do here is to add more then one instruction into the macro, but I don’t know how. Any ideas on how to solve this are highly appreciated. Thanks in advance. Aidman » over and out

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      just a guess, untested

      #define testmacro(x) _asm mov eax, 0 _asm mov ebx, 0

      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_langref___asm.asp[^]


      [

      ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

      Within you lies the power for good; Use it!

      A 1 Reply Last reply
      0
      • A Aidman

        Hi, all :) I am trying to write a high performance library by using inline assembler, but I have encountered a irritating problem. It seems that VC++ refuses to accept multi-instructions within the inline asm section for the macro. For example, I can write a inline assembler macro with the single instruction “mov eax, 0” but that’s it, VC++ refuses to accept anymore instructions. The following code might give a better understanding. #define TestMacro1(x) _asm{ mov eax, 0 } // This works #define TestMacro2(x) _asm{ mov eax, 0; mov ebx, 0 } // This doesn’t So what I am trying to do here is to add more then one instruction into the macro, but I don’t know how. Any ideas on how to solve this are highly appreciated. Thanks in advance. Aidman » over and out

        T Offline
        T Offline
        Toni78
        wrote on last edited by
        #3

        My untested guess would be

        #define TestMacro2(x) _asm{ mov eax, 0 \
        mov ebx, 0 }

        // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

        A R 2 Replies Last reply
        0
        • PJ ArendsP PJ Arends

          just a guess, untested

          #define testmacro(x) _asm mov eax, 0 _asm mov ebx, 0

          http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_langref___asm.asp[^]


          [

          ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

          A Offline
          A Offline
          Aidman
          wrote on last edited by
          #4

          Thank you :) I am most grateful Aidman » over and out

          1 Reply Last reply
          0
          • T Toni78

            My untested guess would be

            #define TestMacro2(x) _asm{ mov eax, 0 \
            mov ebx, 0 }

            // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

            A Offline
            A Offline
            Aidman
            wrote on last edited by
            #5

            When I try to compile this:

            #define TestMacro2(x) _asm{ mov eax, 0 \
            mov ebx, 0 }

            int main() {
            TestMacro2(0);
            return 0;
            }

            I get the following error and warning with VC++: warning C4405: 'mov' : identifier is reserved word error C2400: inline assembler syntax error in 'second operand'; found 'register' Thanks anyway :) Aidman » over and out

            T 1 Reply Last reply
            0
            • T Toni78

              My untested guess would be

              #define TestMacro2(x) _asm{ mov eax, 0 \
              mov ebx, 0 }

              // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

              R Offline
              R Offline
              Ryan Binns
              wrote on last edited by
              #6

              Nope. Won't work. The '\' at the end of the line will cause the two lines to be concatenated, effectively becoming

              #define TestMacro2(x) _asm{ mov eax, 0 mov ebx, 0 }

              You'll have to use PJ's solution to get the result he's after.

              Ryan

              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

              T 1 Reply Last reply
              0
              • R Ryan Binns

                Nope. Won't work. The '\' at the end of the line will cause the two lines to be concatenated, effectively becoming

                #define TestMacro2(x) _asm{ mov eax, 0 mov ebx, 0 }

                You'll have to use PJ's solution to get the result he's after.

                Ryan

                "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                T Offline
                T Offline
                Toni78
                wrote on last edited by
                #7

                It was a shot in the dark. In assembly there are no line delimiters such as ; (I am sure you know this), while PJ's solution seemed to work I thought he could give it a try with my idea. Obviously, it doesn't work. :-D // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

                R 1 Reply Last reply
                0
                • A Aidman

                  When I try to compile this:

                  #define TestMacro2(x) _asm{ mov eax, 0 \
                  mov ebx, 0 }

                  int main() {
                  TestMacro2(0);
                  return 0;
                  }

                  I get the following error and warning with VC++: warning C4405: 'mov' : identifier is reserved word error C2400: inline assembler syntax error in 'second operand'; found 'register' Thanks anyway :) Aidman » over and out

                  T Offline
                  T Offline
                  Toni78
                  wrote on last edited by
                  #8

                  I am sorry Aidman that it didn't work. It was just a suggestion that I didn't test, because I was in a hurry. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

                  1 Reply Last reply
                  0
                  • A Aidman

                    Hi, all :) I am trying to write a high performance library by using inline assembler, but I have encountered a irritating problem. It seems that VC++ refuses to accept multi-instructions within the inline asm section for the macro. For example, I can write a inline assembler macro with the single instruction “mov eax, 0” but that’s it, VC++ refuses to accept anymore instructions. The following code might give a better understanding. #define TestMacro1(x) _asm{ mov eax, 0 } // This works #define TestMacro2(x) _asm{ mov eax, 0; mov ebx, 0 } // This doesn’t So what I am trying to do here is to add more then one instruction into the macro, but I don’t know how. Any ideas on how to solve this are highly appreciated. Thanks in advance. Aidman » over and out

                    T Offline
                    T Offline
                    TheSurrealist
                    wrote on last edited by
                    #9

                    Hi, Did you try: #define TestMacro2(x) { _asm mov eax, 0 _asm mov ebx, 0 } or even #define TestMacro2(x) { \ _asm mov eax, 0 \ _asm mov ebx, 0 \ } Both of the above should work - note the surrounding braces {} are not necessary but are there to make the code look prettier. :) HTH -------------------------------------------- "The mere act of drinking beer in an attempt to measure your tolerance is likely to affect your impression of how many beers you've drunk." -- The Heineken uncertainty principle.

                    1 Reply Last reply
                    0
                    • T Toni78

                      It was a shot in the dark. In assembly there are no line delimiters such as ; (I am sure you know this), while PJ's solution seemed to work I thought he could give it a try with my idea. Obviously, it doesn't work. :-D // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

                      R Offline
                      R Offline
                      Ryan Binns
                      wrote on last edited by
                      #10

                      The __asm is its own separator, so __asm mov ax,0 __asm mov bx,0 is perfectly valid code.

                      Ryan

                      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups