How to set gcc or clang to use Intel syntax permanently for inline asm() statements?

Use -masm=intel and don’t use any .att_syntax directives in your inline asm. This works with GCC and I think ICC, and with any constraints you use. Other methods don’t. (See Can I use Intel syntax of x86 assembly with GCC? for a simple answer saying that; this answer explores exactly what goes wrong, including with … Read more

Why can’t local variable be used in GNU C basic inline asm statements?

You can use local variables in extended assembly, but you need to tell the extended assembly construct about them. Consider: #include <stdio.h> int main (void) { int data1 = 10; int data2 = 20; int result; __asm__( ” movl %[mydata1], %[myresult]\n” ” imull %[mydata2], %[myresult]\n” : [myresult] “=&r” (result) : [mydata1] “r” (data1), [mydata2] “r” … Read more

Alloca implementation

implementing alloca actually requires compiler assistance. A few people here are saying it’s as easy as: sub esp, <size> which is unfortunately only half of the picture. Yes that would “allocate space on the stack” but there are a couple of gotchas. if the compiler had emitted code which references other variables relative to esp … Read more

x86/x64 CPUID in C#

I’m fairly certain you’re being blocked by DEP. The x_CPUIDy_INSNS byte arrays are in a segment of memory marked as data and non-executable. EDIT: That being said, I’ve gotten a version that compiles and runs, but I don’t think gets the right values. Perhaps this will get you along your way. EDIT 2: I think … Read more