Inline Assembler Macros?
-
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 -
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 outjust 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!
-
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 -
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!
-
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
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 -
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
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"
-
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"
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
-
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 -
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 outHi, 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.
-
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
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"