void rotate( unsigned long mask[], int rotateCnt );

此函数将当前64位掩码(mask[])旋转rotateCnt个位置。如果rotateCnt为正,则向左旋转;如果rotateCnt为负,则向右旋转只有rotateCnt的低6位应用于rotateCnt
但是我必须在模拟1个64位寄存器的2个32位寄存器中进行旋转,在两个32位寄存器之间执行64位操作他们让我做两个循环,但我搞不懂?任何h

最佳答案

在使用x86时,请查看shld and shrd你不需要循环(我不懂他们为什么要循环)。
更新
这里有一个DevStudio 2005风格的函数,它使用内联汇编程序来做您想要的事情不要在没有充分理解它是如何工作的(尤其是负数如何做右旋)的情况下将其作为一个解决方案提出,因为你的老师很容易发现你在不知道它是如何工作的情况下复制了它(即老师:“这是如何工作的?”,您:“Errr…”=>失败)。

void Rotate
(
  unsigned *value, // pointer to two 32bit integers
  int count        // number of bits to rotate: >= 0 left, < 0 = right
)
{
  __asm
  {
    mov esi,value
    mov eax,[esi]
    mov edx,[esi+4]
    mov ecx,count
    mov ebx,eax
    shld eax,edx,cl
    shld edx,ebx,cl
    test cl,32
    jz noswap
    xchg edx,eax
noswap:
    mov [esi],eax
    mov [esi+4],edx
  }
}

关于c - 移位2个32位寄存器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10434237/

10-11 16:43