View Full Version : x86 Inline Assembly

Jan 27, 2007, 12:16 PM
I am trying to play around with some assembly commands in Xcode and I'm getting a "Invalid mnemonic 'mov'" error. I have a basic Foundation Tool project setup:

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
mov 0x1, eax
return 0;

I have Google'd a lot and haven't found anything helpful really. I'm assuming I'm missing a compiler switch or something?

(I eventually want to get the CPUID opcode to work, but that gives the same error)

Jan 27, 2007, 01:22 PM
Is gcc getting an -arch i386 somewhere? I can duplicate that message if I force ppc.

For that mov in your example, I'd also check the operand order (the att vs. intel syntax thing drives me nuts, I always forget which is which and ultimately do the right thing, go back to C :p )

Jan 27, 2007, 02:24 PM
This is my opinion : avoid assembler.
Just about anything can be done in C. I write embedded firmware. I / my project, limit assembler to bootup code. That is setting basic access and peripherals. Such as turning on RAM systems and setting up stacks.
You want to access a certain memory location, you can use C.
Sorry if sounds like a rant. I suppose it is. Just trying to help.

I've done much x86 assembler in the mid 80s. So this is similar to me saying don't put your hand in a meat grinder. I'm not sure which is worse :eek:

Jan 27, 2007, 04:41 PM
(I eventually want to get the CPUID opcode to work, but that gives the same error)

Spotlight is your friend: Command-space, type in "cpuid", and it finds a file "cpuid.h" which should contain everything you need.

Jan 28, 2007, 06:32 AM
I don't get that error, I get "suffix or operands invalid for 'mov' "
If I reverse the operands, e.g. mov eax, 0x1 it compiles and runs fine.

This is an Intel iMac, opening XCode and doing a new "Foundation Tool" project.