howto include asm code in c++ (gcc/linux)
-
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. :)
-
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. :)
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
-
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. :)
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 -
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, 2006i 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 ;-(
-
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 ;-(
what about using parenthesis
( )
instead of curly braces{ }
?
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -
what about using parenthesis
( )
instead of curly braces{ }
?
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -
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 ;-(
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...]