+ 1
Need some help with error - too many memory references for `shl'
Have an error trying to put in some inline ASM. I am trying to learn this. https://code.sololearn.com/c1lEdQbJRK3l
6 Answers
+ 4
You got the order of the operands mixed up. CL comes first. Also, you don't have the variable names available in asm. If you want to do it your way, you can use the Linux calling convention, for which num is passed in RDI, power is passed in RSI. Before you return, remember to undo the stack frame using a leave instruction:
int power2( int num, int power )
{
__asm(
"movl %edi, %eax\n" //Get first argument
"movl %esi, %ecx\n" //Get second argument"
"shll %cl, %eax\n" //EAX = EAX * ( 2 to the power of CL )"
"leave;ret;" //Will it return 3^2^5??
);
return -1;
}
Better is to assign the variables to registers for input and output. That will also rid you off some move instructions to charge the proper registers:
int power2( int num, int power )
{
__asm(
"shll %%cl, %%eax\n" //EAX = EAX * ( 2 to the power of CL )"
: "+a" (num)
: "c" (power)
);
return num;
}
+ 2
Thank you. Assembly is really kicking my backside. Your help was much appreciated.
+ 2
You're welcome. Good luck đIf u you want, I can upload some inline asm codes for you too inspect.
+ 1
That would be awesome. I think my difficulties is alot of what registers are being used and for what.
+ 1
All right. I have uploaded a few. You will find them marked [ASM] in my code bits.