0

why i can't use rsi at ror of Assembly code when calling function Assembly from C

With error: invalid combination of opcode and operands

Help me thank you

Assembly code:

section .text
   global  en_code
en_code:
    mov ax,[rdi]
    ror ax,rsi ;????
    mov [r13],ax
    mov rax,r13
    ret

C code:

#include<stdio.h>
#include<string.h>
extern char* en_code();
int main()
{
    printf("Here:%s .\n",en_code("ng",2));
    return 0; 
}
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • I'd use `mov ecx, esi` / `ror word [rdi], cl` / `mov rax, rdi` if you insist on taking the 16-bit input to be rotated by reference in memory, instead of in a register itself to return as a uint16_t. `r13` isn't used for arg-passing in x86-64 System V, IDK why you're loading from the source string and storing through R13. – Peter Cordes Jun 13 '20 at 11:39
  • Also, you don't need asm to get rotate instructions. C compilers can emit them: [Best practices for circular shift (rotate) operations in C++](https://stackoverflow.com/q/776508) – Peter Cordes Jun 13 '20 at 11:41
  • I have no experience with assembly and trying to make a few simple examples – Nghĩa Văn Jun 13 '20 at 14:42

1 Answers1

2

The only ROR combination that takes two registers requires that the shift count be in CL. You can rotate a register or memory operand but the shift count must either be immediate or passed in CL.

From RCL/RCR/ROL/ROR — Rotate

(intel syntax):

REX.W + D3 /1 | ROR r/m64, CL | MC | Valid | N.E. | Rotate 64 bits r/m64 `right CL times. Uses a 6 bit count. |`  
SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • Thank you,but I have the parameter passed down from C and its value is stored in RSI so how can I pass it to CL, I tried / mov CL, [RSI] / but it didn't work. – Nghĩa Văn Jun 13 '20 at 14:50