How do I assign a simple constant like "10" to a register in inline assembly and move it to an output variable in gcc c++?
int eax;
asm("label1:"
"mov $100000000, %%ecx"
"dec %%ecx"
"cmp $0, %%ecx"
"jnz label1"
"mov %%ecx, %%eax"
: "=a"(eax)
: : );
This is the error I get: "Error: bad register name `%ecxmov $0'"
Edit: I fixed it in a way that the program runs by adding "\n\t" to each line. I also added ecx as a clobber. But Now I get an endless loop even though it should break when ecx is 0.
int eax;
asm("label1:\n\t"
"mov $100000000, %%ecx\n\t"
"dec %%ecx\n\t"
"cmp $0, %%ecx\n\t"
"jnz label1\n\t"
"mov %%ecx, %%eax\n\t"
: "=a"(eax)
: : "ecx");