Here is my code:
__asm__ ("movl %3, %%ecx\n"
"movl $0, %%edx\n"
"movl %2, %%eax\n"
"1:\n"
"movl %2, %%ebx\n"
"movl %%ecx, %1\n" // Debugging
//"movl %%edx, %3\n" // Debugging
//"movl %%eax, %4\n" // Debugging
"imul %%ebx, %%eax\n"
"inc %%edx\n"
"cmp %%edx, %%ecx\n"
"jle 1b\n"
"movl %%eax, %0\n"
: "=r" (retval), "=r" (ecxval)
: "r" (val), "r" (pow));
(ecxval) is for debugging my code. (retval) is the return variable.
When I use 2 I always get either 4 or 0 which is weird.
(1:) is my label for my loop. (val) is the input value. (pow) is the power number. for example val: 2, pow: 5 is 2^5.
At the start of the program ecx is set to the val, edx is the counter so its set to 0, eax is set to the val. In the loop my code should move the contents of val to ebx multiply eax by ebx and the result is put into eax, then edx is increased by 1 and edx is compared to ecx and if less than or equal to it jumps and at the end the contents of eax are moved into the return value.
I've tried all ways I can think of to debug but with 2^(an even number) it always results in 4 and 2^(an uneven number) it always results in 0. But the expected result is for example 2^2 = 4, 2^3 = 8.