Jump to content
  • Advertisement
Sign in to follow this  
V-man

inline assembly, C++

This topic is 4367 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have some C++ code and it contains inline assembly. It uses the __asm keyword that is VC++ specific. gcc doess't like it. How to compile this thing?

Share this post


Link to post
Share on other sites
Advertisement
Thanks, you are the best.
I hwas searching for gcc+assembly and gcc+sse and it was giving topics I was not interested in.

Share this post


Link to post
Share on other sites
The code has been written a long time ago and also there is IA32 code.

gcc seems to have a different format for the inline assmebly


asm ("mov eax, 0;
mov ecx, 1;
call _foo"
: /* no outputs */
: "g" (from), "g" (to)
: "eax", "ecx"
);


while in VC++ it's

__asm
{
mov eax, 0
mov ecx, 1
call _foo
}


There is some other formats in gcc but they all require a lot of change that is best for a automation tool. Anyone have one handy?

Share this post


Link to post
Share on other sites
I tried to compile this but it keeps given a error message.
It gives the same error message for the mov instruction : "too many memory references"


/////// I typed this to compile
linux:/MyDocuments # gcc -fPIC -fomit-frame-pointer -g -c asm.cpp
/tmp/cckuMs2Z.s: Assembler messages:
/tmp/cckuMs2Z.s:32: Error: too many memory references for `xor'


//////CODE
int main()
{
__asm__ __volatile__
(
//"mov eax,eax"
"xor eax, eax"

: //No output registers
: //No input registers
: "eax", "ecx", "edx" //Clobber list
);
//".byte 0x0f; .byte 0x31" return 1;
}

Share this post


Link to post
Share on other sites
Try looking at this. It's for DJGPP, but the information applies to any GCC.

For your current problem, you need to prefix the register names with '%', or they will instead be considered to be memory accesses.

Share this post


Link to post
Share on other sites
I think I tried that one. It didn't work.
Also, I consulted that page. It says the % is for the AT&T syntax.
I use Intel.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

int main()
{
__asm__ __volatile__
(
//"mov eax,eax"
"xor %%eax, %%eax"

: //No output registers
: //No input registers
: "eax", "ecx", "edx" //Clobber list
);
//".byte 0x0f; .byte 0x31" return 1;
}


should work, note double %

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
I think I tried that one. It didn't work.
Also, I consulted that page. It says the % is for the AT&T syntax.
I use Intel.

GCC and its assembler use AT&T syntax. In your example, the double percent-sign is required to prefix the registers.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!