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. Managed C++/CLI
  4. howto include asm code in c++ (gcc/linux)

howto include asm code in c++ (gcc/linux)

Scheduled Pinned Locked Moved Managed C++/CLI
c++linuxhelp
7 Posts 3 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.
  • G Offline
    G Offline
    gecool
    wrote on last edited by
    #1

    hello everyone. I need to include a few lines of asm code (crc32 routine) in c++ code. I tried asm(" asm-code-here");, or _asm { ... }, or __asm__ { ...} but none had worked. The asm code is: asm ("push esi ; push edi ; mov eax, dwCrc32 ; mov ecx, [eax]; mov edi, Crc32Table ; lea esi, buf ; mov ebx, length ; lea edx, [esi + ebx] ; crc32loop: xor eax, eax ; mov bl, byte ptr [esi] ; mov al, cl ; inc esi; xor al, bl ; shr ecx, 8 ; mov ebx, [edi + eax * 4]; xor ecx, ebx ; cmp edx, esi ; jne crc32loop ; pop edi ; pop esi ; mov eax, dwCrc32 ; mov [eax], ecx"); P.S. i tried adding a \ character to each end of line, or make a long line out of it, but i couldn't even compile it. Please help. :)

    J T 2 Replies Last reply
    0
    • G gecool

      hello everyone. I need to include a few lines of asm code (crc32 routine) in c++ code. I tried asm(" asm-code-here");, or _asm { ... }, or __asm__ { ...} but none had worked. The asm code is: asm ("push esi ; push edi ; mov eax, dwCrc32 ; mov ecx, [eax]; mov edi, Crc32Table ; lea esi, buf ; mov ebx, length ; lea edx, [esi + ebx] ; crc32loop: xor eax, eax ; mov bl, byte ptr [esi] ; mov al, cl ; inc esi; xor al, bl ; shr ecx, 8 ; mov ebx, [edi + eax * 4]; xor ecx, ebx ; cmp edx, esi ; jne crc32loop ; pop edi ; pop esi ; mov eax, dwCrc32 ; mov [eax], ecx"); P.S. i tried adding a \ character to each end of line, or make a long line out of it, but i couldn't even compile it. Please help. :)

      J Offline
      J Offline
      James Gupta
      wrote on last edited by
      #2

      From memory, in the MS compilers i think you can use inline asm by typing "_asm" where you want to start the assembly, and then "asm_" at the end it may be the other way around though lol

      1 Reply Last reply
      0
      • G gecool

        hello everyone. I need to include a few lines of asm code (crc32 routine) in c++ code. I tried asm(" asm-code-here");, or _asm { ... }, or __asm__ { ...} but none had worked. The asm code is: asm ("push esi ; push edi ; mov eax, dwCrc32 ; mov ecx, [eax]; mov edi, Crc32Table ; lea esi, buf ; mov ebx, length ; lea edx, [esi + ebx] ; crc32loop: xor eax, eax ; mov bl, byte ptr [esi] ; mov al, cl ; inc esi; xor al, bl ; shr ecx, 8 ; mov ebx, [edi + eax * 4]; xor ecx, ebx ; cmp edx, esi ; jne crc32loop ; pop edi ; pop esi ; mov eax, dwCrc32 ; mov [eax], ecx"); P.S. i tried adding a \ character to each end of line, or make a long line out of it, but i couldn't even compile it. Please help. :)

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

        the keyword is __asm { ... } (two underscores...) with gcc, also try this (a little search on google might have help you) :

        asm ("pushl %eax\n\t"
        "movl $0, %eax\n\t"
        "popl %eax");

        ps: this is the C++/CLI forum, ,so only Managed C++ questions should be asked here...


        TOXCCT >>> GEII power
        [toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -- modified at 8:27 Tuesday 31st January, 2006

        G 1 Reply Last reply
        0
        • T toxcct

          the keyword is __asm { ... } (two underscores...) with gcc, also try this (a little search on google might have help you) :

          asm ("pushl %eax\n\t"
          "movl $0, %eax\n\t"
          "popl %eax");

          ps: this is the C++/CLI forum, ,so only Managed C++ questions should be asked here...


          TOXCCT >>> GEII power
          [toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -- modified at 8:27 Tuesday 31st January, 2006

          G Offline
          G Offline
          gecool
          wrote on last edited by
          #4

          i tried that out , but didn't work. i even added -masm=intel on the command line but it turned out of no use. That is i don't really like/know at&t (% stuff) conventions, so i preffered to stick with intel. When i use __asm, or asm or _asm_ or __asm__, i get the same error: "syntax error before '}' ... " . i dug in google results, but i didn't worked it out yet ;-(

          T 1 Reply Last reply
          0
          • G gecool

            i tried that out , but didn't work. i even added -masm=intel on the command line but it turned out of no use. That is i don't really like/know at&t (% stuff) conventions, so i preffered to stick with intel. When i use __asm, or asm or _asm_ or __asm__, i get the same error: "syntax error before '}' ... " . i dug in google results, but i didn't worked it out yet ;-(

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            what about using parenthesis ( ) instead of curly braces { } ?


            TOXCCT >>> GEII power
            [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

            G 1 Reply Last reply
            0
            • T toxcct

              what about using parenthesis ( ) instead of curly braces { } ?


              TOXCCT >>> GEII power
              [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

              G Offline
              G Offline
              gecool
              wrote on last edited by
              #6

              i tried that too. whith one big string, like asm ("mov eax, ebx" "lea ..." "xor eax, eax"), or like asm ("mov ... ; \ lea .... ; \ ") I tried without the semicolon too, but didn't work ;-(

              T 1 Reply Last reply
              0
              • G gecool

                i tried that too. whith one big string, like asm ("mov eax, ebx" "lea ..." "xor eax, eax"), or like asm ("mov ... ; \ lea .... ; \ ") I tried without the semicolon too, but didn't work ;-(

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

                and my last try :

                asm("mov eax, ebx");
                asm("lea ...");
                asm("xor eax, eax");


                TOXCCT >>> GEII power
                [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

                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