1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

x86 Inline Assembly

Discussion in 'Mac Programming' started by kainjow, Jan 27, 2007.

  1. Moderator emeritus

    kainjow

    #1
    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:

    Code:
    #import <Foundation/Foundation.h>
    int main (int argc, const char * argv[])
    {
      asm
      {
        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)
     
  2. macrumors G3

    iMeowbot

    #2
    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 )
     
  3. macrumors 65816

    Flynnstone

    #3
    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:
     
  4. macrumors G5

    gnasher729

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

    #5
    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.
     

Share This Page