Sign in to follow this  
Last Attacker

Assembly Instricts

Recommended Posts

Hi guys! I'm wondering if the GCC C++ compiler has any instrict functions for assembly equivalents like in Visual C++. What I mean is, instead of doing direct inline assembly, just call a function that performs that inline assembly itself. It may sound crazy but it would be a very good idea if you want your program to compile in Visual C++ and with the GCC (MingW I believe) C++ compiler, since I'm not willing to learn the AT&T syntax of GCC's inline assembly. Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Last Attacker
What I mean is, instead of doing direct inline assembly, just call a function that performs that inline assembly itself.


What do you mean?

Share this post


Link to post
Share on other sites
Do you mean "intrinsics"?

Quote:
Original post by Last Attacker
I'm not willing to learn the AT&T syntax of GCC's inline assembly.


You should always be willing to learn something if it will allow you to get the job done. Here is a useful article on inline assembly in DJGPP, which is another port of gcc, just like MinGW.

Share this post


Link to post
Share on other sites
Quote:
Original post by bakery2k1
Here is a useful article on inline assembly in DJGPP, which is another port of gcc, just like MinGW

Thanks for that page.

Quote:
Original post by bakery2k1
Do you mean "intrinsics"?

Sorry I thought that you called it Instricts.

Quote:
Original post by Endar
What do you mean?

What I mean is something like this (this is only an example):

int a, b;
ist_swap(a, b);




Which should be an equivalent to:

int a, b;

_asm{
mov eax, [a]
mov ebx, [b]
mov [a], ebx
mov [b], eax
}


Share this post


Link to post
Share on other sites
The .o files compiled by nasm is cool but I want to limit it to the C++ compiler. Apparently the compiler can do (to optimize) more with inline assembly stuff than with assembly code that gets included. I dunno, we did a practical on it at university where we had to write an assembly function to find the smallest element in the array the fastest sothat the C program's selection sort function can use that function to sort a large array of numbers.
I later (after the practicals were marked, etc) got the solution and decided to tweak it some more to make it the fastest function possible and on those Intel P4 1.7GHz Celeron machines it took 16 seconds average to sort an array of 100000 elements.
When I wrote a standard C function and used -O3 in GCC to compile, it took 15 seconds average.
Also, the reason for that is if I want to use nasm, I have to make the makefiles for Visual Studio, DevCpp, Linux (when compiling it straight there), etc. I just want the guy to compile it without having to download nasm first and without giving me more work to do than I have too, know what I mean?

Does anyone know maybe an Intel to GAS assembly translator (and vice-versa), one where all those parameters are also present when you want to move values around with the "=r" stuff and who knows what else is required just to make a move instruction? Like, you type in what you want in Intel syntax and the translater, translates it to GAS syntax with the best possible match to what I want. That'll be so cool. I know DevCpp has something like that but it doesn't have the other parameter stuff like I talked about the "=r" stuff. Man, what do they call it...

Well, its this stuff:
asm ("leal (%%ebx,%%ebx,4), %%ebx" : "=b" (x) : "b" (x) );

everything from the first ':'. Thats the stuff that bugs me the most about GAS!

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Last Attacker
Does anyone know maybe an Intel to GAS assembly translator (and vice-versa), one where all those parameters are also present when you want to move values around with the "=r" stuff and who knows what else is required just to make a move instruction? Like, you type in what you want in Intel syntax and the translater, translates it to GAS syntax with the best possible match to what I want. That'll be so cool. I know DevCpp has something like that but it doesn't have the other parameter stuff like I talked about the "=r" stuff. Man, what do they call it...

Well, its this stuff:
asm ("leal (%%ebx,%%ebx,4), %%ebx" : "=b" (x) : "b" (x) );

everything from the first ':'. Thats the stuff that bugs me the most about GAS!

Thanks


ID software published the GAS-to-Intel (and/or vice-versa? - I am not sure) converter they had used for their Quake 1 assembly code. I have certainly seen it in the Q1 source available at ID's website, but I don't know if it is what you are looking for.

Share this post


Link to post
Share on other sites
Quote:
Original post by Last Attacker
Does anyone know maybe an Intel to GAS assembly translator (and vice-versa), one where all those parameters are also present when you want to move values around with the "=r" stuff and who knows what else is required just to make a move instruction? Like, you type in what you want in Intel syntax and the translater, translates it to GAS syntax with the best possible match to what I want. That'll be so cool. I know DevCpp has something like that but it doesn't have the other parameter stuff like I talked about the "=r" stuff. Man, what do they call it...


Intel2GAS is a converter that will convert assembler source files written for NASM to files that can be assembled using the GNU Assembler (GAS), on the i386 platform. It provides support for basic MMX instructions as well.

Quote:
Original post by Last Attacker
Well, its this stuff:
asm ("leal (%%ebx,%%ebx,4), %%ebx" : "=b" (x) : "b" (x) );

everything from the first ':'. Thats the stuff that bugs me the most about GAS!


I think that is specific to gcc. I prefer the AT&T syntax but that's me. One thing that AT&T has going for it is that there is only one way to express complex addressing forms. To repeat what I wrote here:

Quote:

AT&T syntax expresses effective addresses in a less ambiguous manner as well. Consider, with Intel syntax the following are equivalent:

[base+index*scale+displacement]
[index*scale+base][displacement]
[index*scale+displacement][base]
[base+displacement][index*scale]
[displacement+base][index*scale]
displacement[base][index*scale]
displacement[index*scale][base]

With AT&T there is only one way to express it

displacement(base,index,scale)

Share this post


Link to post
Share on other sites
Quote:
Original post by LessBread
I think that is specific to gcc. I prefer the AT&T syntax but that's me. One thing that AT&T has going for it is that there is only one way to express complex addressing forms. To repeat what I wrote here:

Quote:
AT&T syntax expresses effective addresses in a less ambiguous manner as well. Consider, with Intel syntax the following are equivalent:

[base+index*scale+displacement]
[index*scale+base][displacement]
[index*scale+displacement][base]
[base+displacement][index*scale]
[displacement+base][index*scale]
displacement[base][index*scale]
displacement[index*scale][base]

With AT&T there is only one way to express it

displacement(base,index,scale)


Maybe, but I'm used to the C way of traversing through a 1D array in a 2D way. You know? Like, a 2x2 int matrix would be a 4x1 int array. So for me to use any of the Intel stuff to traverse wouldn't bother me. And basically "displacement(base,index,scale)" is probably the only easy thing to do with AT&T assembly. Not that I want to argue with you or anything but I hope you agree with me that Intel sytax is much easier to read and understand than the AT&T's syntax.
Anyway, looks to me that I might have to know AT&T.

Quote:
Intel2GAS is a converter that will convert assembler source files written for NASM to files that can be assembled using the GNU Assembler (GAS), on the i386 platform. It provides support for basic MMX instructions as well.

Thanks, I'll definately be using that!

Share this post


Link to post
Share on other sites
Quote:
Original post by Last Attacker
Maybe, but I'm used to the C way of traversing through a 1D array in a 2D way. You know? Like, a 2x2 int matrix would be a 4x1 int array. So for me to use any of the Intel stuff to traverse wouldn't bother me. And basically "displacement(base,index,scale)" is probably the only easy thing to do with AT&T assembly. Not that I want to argue with you or anything but I hope you agree with me that Intel sytax is much easier to read and understand than the AT&T's syntax.
Anyway, looks to me that I might have to know AT&T.


Sorry, I don't agree with you. I think Intel is easier for you because that's what you learned first. I learned AT&T first so I think it's easier. I'm sure it's easier for Russians to read and understand Russian than it is for them to read and understand English or Chinese.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this