+ 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

31st Mar 2022, 1:24 AM
William Owens
William Owens - avatar
6 odpowiedzi
+ 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; }
31st Mar 2022, 4:29 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
Thank you. Assembly is really kicking my backside. Your help was much appreciated.
31st Mar 2022, 11:07 AM
William Owens
William Owens - avatar
+ 2
You're welcome. Good luck 🍀If u you want, I can upload some inline asm codes for you too inspect.
31st Mar 2022, 11:22 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
That would be awesome. I think my difficulties is alot of what registers are being used and for what.
31st Mar 2022, 10:29 PM
William Owens
William Owens - avatar
+ 1
All right. I have uploaded a few. You will find them marked [ASM] in my code bits.
1st Apr 2022, 5:56 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar