Search code examples
cassemblyx86-64bit-shift

how to use parameters of function C to rotate right in Assembly code


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; 
}

Solution

  • 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. |`