内联汇编代码求助
麦田追风 2010-01-04 10:09:54 我这有个C语言内联汇编的代码,现在编译器不支持内联汇编关键字
小弟不懂汇编,麻烦大侠帮我解释下下面内联汇编代码,最好是改写成C
小弟不胜感激
WORD cmsLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p)
{
int xDomain = p -> Domain;
if (Value == 0xffff) return LutTable[p -> Domain];
else
__asm {
xor eax, eax
mov ax, word ptr ss:Value
mov edx, ss:xDomain
mul edx // val3 = p -> Domain * Value;
shld edx, eax, 16 // Convert it to fixed 15.16
shl eax, 16 // * 65536 / 65535
mov ebx, 0x0000ffff
div ebx
mov ecx, eax
sar ecx, 16 // ecx = cell0
mov edx, eax // rest = (val2 & 0xFFFFU)
and edx, 0x0000ffff // edx = rest
mov ebx, ss:LutTable
lea eax, dword ptr [ebx+2*ecx] // Ptr to LUT
xor ebx, ebx
mov bx, word ptr [eax] // EBX = y0
movzx eax, word ptr [eax+2] // EAX = y1
sub eax, ebx // EAX = y1-y0
js IsNegative
mul edx // EAX = EAX * rest
shld edx, eax, 16 // Pass it to fixed
sal eax, 16 // * 65536 / 65535
mov ecx, 0x0000ffff
div ecx
add eax, 0x8000 // Rounding
sar eax, 16
add eax, ebx // Done!
}
RET((WORD) _EAX);
IsNegative:
__asm {
neg eax
mul edx // EAX = EAX * rest
shld edx, eax, 16 // Pass it to fixed
sal eax, 16 // * 65536 / 65535
mov ecx, 0x0000ffff
div ecx
sub eax, 0x8000
neg eax
sar eax, 16
add eax, ebx // Done!
}
RET((WORD) _EAX);
}