Page 1 of 1

I am in trouble,who can help me?

Posted: Thu Apr 15, 2010 2:28 pm
by Alex Wang
Recently , I am reading <<Tricks of the 3D Game Programming Gurus>>.There are two functions that one named Mem_Set_QUAD,and other named Mem_Set_WORD.
inline void Mem_Set_QUAD(void *dest,UINT data,int count)
{
_asm
{
mov edi ,dest;
mov ecx,count;
mov eax,data;
rep stosd;
}
}
inline void Mem_Set_WORD(void *dest,UNSHORT data,int count)
{
_asm
{
mov edi,dest;
mov ecx,count;
mov ax,data;
rep stosw;
}
}
But I don't konw how can I chang it and let it work under the codelite.Who can help me?
Thanks a lot.

Re: I am in trouble,who can help me?

Posted: Thu Apr 15, 2010 2:32 pm
by eranif
Alex Wang wrote:But I don't konw how can I chang it and let it work under the codelite
There is no such thing "work under the codelite" - if you can compile it with gcc/g++/vc++ then it should be OK - if not, then you should consult the relevant forums

Eran

Re: I am in trouble,who can help me?

Posted: Thu Apr 15, 2010 2:51 pm
by Alex Wang
eranif wrote:
Alex Wang wrote:But I don't konw how can I chang it and let it work under the codelite
There is no such thing "work under the codelite" - if you can compile it with gcc/g++/vc++ then it should be OK - if not, then you should consult the relevant forums

Eran
Thank you for your reply.But I can't compile it.En, I know there are some differences between intel asm and at&t asm.Maybe I should consult the relevant forums.

Re: I am in trouble,who can help me?

Posted: Sat Apr 17, 2010 10:38 pm
by Alex Wang
I think I find the way.The solution is following:
inline void Mem_Set_QUAD( void *dest, unsigned int data, int count )
{
__asm__ __volatile__
(
"mov %0,%%edi\n\t"
"mov %1,%%ecx\n\t"
"mov %2,%%eax\n\t"
"rep stosb"
: :"d"(dest),"c"(count),"a"(data)
);
}
And we can call it like this:
char dest[4];
Mem_Set_QUAD(dest,1,4);
for(int i=0;i<4;i++)
{
cout<<static_cast<int>(dest)<<endl;

}
Of course it still fills using single byte,because "stosb".And I can't use the "stosd",once I use "stosd",it tells me:no such instruction:'stosd'.

Re: I am in trouble,who can help me?

Posted: Tue Apr 20, 2010 4:10 pm
by Alex Wang
The lastest solution is that:

inline void Mem_Set_QUAD(void *dest,unsigned int data,int count)
{
__asm__ __volatile__
(
"mov %0,%%edi\n\t"
"mov %1,%%ecx\n\t"
"mov %2,%%eax\n\t"
"rep stosl"
: :"D"(edi),"c"(count),"a"(data)
);
}
And we can do like this:
char dest[16];
//the count is 16/4,if the length is odd numbers,the count is length/4+length%4,because it fills using four bytes
Mem_Set_QUAD(dest,1,4);