我正在尝试将以下 C 代码转换为程序集:
void write (int bitpos, unsigned short sample)
{
int pos = bitpos / 16;
int posA = bitpos - pos * 16;
unsigned short write1 = sample >> posA;
}
我在换档操作中不断出错。我看过书中的一些例子,但我不明白有什么问题。我认为这可能是因为我想要转移的数量是一个变量。我想知道实现这一目标的正确方法是什么?
这是我尝试过的:
//int pos = bitpos / 16;
mov eax, 0
mov eax, [bitpos] // eax= bitpos
cdq
mov ecx, 16
idiv ecx //ecx = pos
//int posA = bitpos - pos * 16;
mov ebx, ecx //ebx = pos
imul ebx, 16 // ebx = pos*16
sub eax, ebx // eax = posA
//unsigned short write1 = sample >> posA;
mov bx, [sample]
shr bx, eax // This is the part that is not working.
错误说:错误的操作数类型。错误代码:C2415