1
我有以下代码来计算Visual Studio程序集中的左/右旋转。使用GCC程序集的移动次数向左/向右旋转
template<class T>
inline T rotr(T x, unsigned char moves){
unsigned char temp;
__asm{
mov temp, CL
mov CL, moves
ror x, CL
mov CL, temp
};
return x;
}
template<class T>
inline T rotl(T x, unsigned char moves){
unsigned char temp;
__asm{
mov temp, CL
mov CL, moves
rol x, CL
mov CL, temp
};
return x;
}
1-我们如何编写gcc的等效asm代码。
2-是否有更好的方法在Visual Studio程序集中编写它?
VC++在标准库中有'_rotl' /'_rotr'(用于'int's)和'_rotl64' /'_rotr64'用于'long long')。 –
同样,gcc(气体)x86程序集有rol/ror(旋转和不包含进位)和rcl/rcr(旋转包含进位)。 – gnometorule