I've been going through a project I'm working on and rewriting some code into inline assembly. Whenever I use the following code:
__asm xor eax, eax
in Visual Studio (2003) I get the following error:
error C2400: inline assembler syntax error in 'opcode'; found 'XOR'
I cannot find any information why this would generate an error or what I can do to correct it. Does anybody know what I am doing wrong here?
Spara
__asm xor eax, eax
in Visual Studio (2003) I get the following error:
error C2400: inline assembler syntax error in 'opcode'; found 'XOR'
I cannot find any information why this would generate an error or what I can do to correct it. Does anybody know what I am doing wrong here?
Spara
i don't seem to get that error when i compile that in vs2003.. its probably the code before the xor that causes the error..
There is no code before that that really matters. I can plop that one line anywhere and generate the error. Replace it with __asm mov eax, 0 and everything works fine. I've tried it on two computer, one running 2002 and the other 2003 and get the same result. That's the only opcode that doesn't seem to work.
Spara
Spara
that's odd, it works on all my systems..
I can't seem to reproduce the error at all, can you attach your project files so I can check it out?
I can't seem to reproduce the error at all, can you attach your project files so I can check it out?
Code like this:
{
#define xor ^
__asm xor eax, eax
}
will produce such an error. Check your defines/macros.
{
#define xor ^
__asm xor eax, eax
}
will produce such an error. Check your defines/macros.
Ah hah! I did #define xor ^ because I think it's a counterintuitive symbol. Never realized the preprocessor directives worked on inline assembly too. Thank you for clearing up my misunderstanding.
Spara
Spara
preprocessor directives are applied blindly without regard to context - use as little as possible.
You'll get used to ^ after a while - otherwise you should probably pick up another language :) - OTOH, apparently "and, or, xor, not" etc are supposed to be keywords in C++ (yuck!), but with MSVC you have to include iso646.h, which #defines them...
You'll get used to ^ after a while - otherwise you should probably pick up another language :) - OTOH, apparently "and, or, xor, not" etc are supposed to be keywords in C++ (yuck!), but with MSVC you have to include iso646.h, which #defines them...
The part that got me was the fact that the error message mentioned "XOR". If it had said
syntax error in 'opcode'; found '^'
I would have known right away what happened. I'll try and get use to the carrot-as-xor symbol or just switch to pure assembly. Thanks for the advice.
Spara
syntax error in 'opcode'; found '^'
I would have known right away what happened. I'll try and get use to the carrot-as-xor symbol or just switch to pure assembly. Thanks for the advice.
Spara
The part that got me was the fact that the error message mentioned "XOR". If it had said
syntax error in 'opcode'; found '^'
I would have known right away what happened.
That was the first thing I did when I realized what was wrong. __asm ^ eax, eax produces exactly the same error message include the 'XOR' bit. It's slightly ambiguous, but I guess the moral is don't #define anything that is also an assembly opcode.
Spara
Spara
couldn't you just do return null or something?
evlncrn8: if the "xor eax, eax" is used for return value, sure (and in that case, the use of inline assembly would be very very silly :)) - but it might be used in some algorithm.
I've gotten into a habit of clearing registers with xor reg, reg statement. I could always just do mov reg, 0 to get the same result and bypass that particular error. My problem came in when I was encrypting/decrypting data with the xor statement. It's pretty necessary at that point and prompted me to place my ignorance in the public domain for all to see.
Spara
Spara