我必须使用内联asm找到两点之间的距离,但是我被卡住了,因为加上两个坐标差异的幂后我得到的数字对于32位寄存器来说太大了。
#include <stdio.h>
void main()
{
// Input
unsigned int Point = 0xFFFFFFFF;
unsigned int PointSet = 0x000A0003
unsigned int dist=0;
/*
every point is a dword and the least significant word is the x coord while the other is the y coord
so for our point it would be (3,10) in decimal and the other point (FFFF,FFFF)
*/
//sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
__asm
{
xor eax,eax
mov eax, dword ptr PointSet[0]
shr eax,16d //ax is x1
xor ebx,ebx
mov bx, word ptr PointSet[0] //bx is y1
mov ecx, 0xFFFF //x2
mov edx, 0xFFFF//y2
sub ecx,eax //(x2-x1)
sub edx,ebx //(y2-y1)
imul ecx,ecx //(x2-x1)^2
imul edx,edx //(x2-x1)^2
add ecx,edx //here the number is way too big to stay in a simple 32 bit register
push esp
mov dword ptr[esp], ecx
fild dword ptr[esp]
fsqrt
fst dword ptr[esp]
mov ecx,esp
}
printf("%d",dist);
getchar();
}