Question: I am using the following code to set the cr0 bit to disable cache.
When I compile this

```
#include <stdio.h>

int main()
{
        __asm__("pushl  %eax\n\t"
                "mov    %cr0,%eax;\n\t"
                "orl    $(1 << 30),%eax;\n\t"
                "mov    %eax,%cr0;\n\t"
                "wbinvd\n\t"
                "popl   %eax"
);

        return 0;
}

```

I am getting error saying that the operands are invalid for mov.

Can anyone please point me to a good gcc x86-64 guide for doing these kinds of things?
Also what exactly is wrong with the above code?

Answer: 
Try this:
 "mov %%cr0, %%eax \n"

A simple % is interpreted as user argument (I think).

You should read [this](http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html)
The code compiles OK for me on 32-bit x86 bit not on x86-64 - this is with gcc 4.2.1 on Mac OS X:

```
$ gcc -Wall -m32 cr0.c -o cr0
$

```

No errors or warnings.

```
$ gcc -Wall -m64 cr0.c -o cr0
/var/folders/.../cce0FYAB.s:9:suffix or operands invalid for `push'
/var/folders/.../cce0FYAB.s:10:suffix or operands invalid for `mov'
/var/folders/.../cce0FYAB.s:12:suffix or operands invalid for `mov'
/var/folders/.../cce0FYAB.s:14:suffix or operands invalid for `pop'
$

```

So I guess there are deeper issues than just the `mov %eax,%cr0` instruction here with asm on x86-64.

Looking at the x86-64 ISA it seems that you probably need something like this for x86-64:

```
#include <stdio.h>

int main()
{
        __asm__("pushq  %rax\n\t"
                "movq    %cr0,%rax\n\t"
                "orl    $(1 << 30),%eax\n\t"
                "movq    %rax,%cr0\n\t"
                "wbinvd\n\t"
                "popq   %rax"
);

        return 0;
}

```

I don't know if this works but it at least compiles/assembles OK:

```
$ gcc -Wall -m64 cr0.c -o cr0
$ 

```