I am in trouble,who can help me?

CodeLite installation/troubleshooting forum
Alex Wang
CodeLite Enthusiast
Posts: 12
Joined: Tue Mar 09, 2010 4:22 pm
Genuine User: Yes
IDE Question: c++
Contact:

I am in trouble,who can help me?

Post 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.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

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

Post 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
Make sure you have read the HOW TO POST thread
Alex Wang
CodeLite Enthusiast
Posts: 12
Joined: Tue Mar 09, 2010 4:22 pm
Genuine User: Yes
IDE Question: c++
Contact:

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

Post 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.
Alex Wang
CodeLite Enthusiast
Posts: 12
Joined: Tue Mar 09, 2010 4:22 pm
Genuine User: Yes
IDE Question: c++
Contact:

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

Post 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'.
Alex Wang
CodeLite Enthusiast
Posts: 12
Joined: Tue Mar 09, 2010 4:22 pm
Genuine User: Yes
IDE Question: c++
Contact:

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

Post 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);
Post Reply