求大规模计算负数的方法!
本帖最后由 zhouxicai 于 2013-01-23 21:36:19 编辑
int x = 3;
x = -x;
struct count
{
int x1;
int x2;
int x3;
int x4;
int x5;
int x6;
}
count c;
int* p = (int*)&c
for (int i = 0; i < 6; ++i, ++p)
{
*p = -*p;
}
#include <stdio.h>
#include <memory.h>
struct count {
int x1;
int x2;
int x3;
int x4;
int x5;
int x6;
} c,*p;
int main() {
p=&c;
__asm {
push ecx
push edi
mov eax,3
mov ecx,6
mov edi,p
rep stosd
pop edi
pop ecx
}
printf("%d,%d,%d,%d,%d,%d\n",c.x1,c.x2,c.x3,c.x4,c.x5,c.x6);
__asm {
push ecx
push edi
push esi
mov esi,p
mov edi,esi
mov ecx,6
next:
lodsd
neg eax
stosd
loop next
pop esi
pop edi
pop ecx
}
printf("%d,%d,%d,%d,%d,%d\n",c.x1,c.x2,c.x3,c.x4,c.x5,c.x6);
return 0;
}
//3,3,3,3,3,3
//-3,-3,-3,-3,-3,-3