2
votes

Im actually learning assembly and I went with Gas, but the problem is:

1) I only know Intel syntax and I saw in a page Gas with intel syntax is not very good optimized in some cases. Is this correct or im wrong? Im talking about this web:

http://wiki.osdev.org/FASM

2) Then I also saw (i dont remember the page) that the fact gas can assemble in several architectures also slows the assembled program. Is it right?

3) Which assembler do you recommend my that produces HIGHLY OPTIMIZED CODE? I saw in other questions that each assembler in some cases can convert to different opcodes. I was between YASM, FASM, GAS and NASM but other recomendations are accepted. FASM is know to be very fast...

Thanks a lot! Keep that great community!

1
To number 2: That fact may make gas run slower, but it will have no effect on the executable built from it.ughoavgfhw
You seem to confuse the speed of the assembling and the speed of the executed code. As Jerry wrote, almost all optimization must be done by you, besides some minor code size optimizations.Gunther Piez
Compilers optimize. Assemblers don't (at least, very little). The reason you're using it is to tell it exactly what machine language you want. If you want something that optimizes, use a compiler.Mike Dunlavey
Assemblers run at blazing speed. Don't worry about that aspect. It is possible for an assembler to choose encodings that save a cycle here and there on a particular microarchitecture, but in the grand scheme it is very unlikely to matter. Modern processors have incredible instruction decoding bandwidth.doug65536
Here's an example of a minor microarchitectural optimization: ROR on haswell. The short form which rotates by 1 bit is actually worse than the long form that rotates by an immeditate constant. An assembler might choose the long form to "optimize" even though the short form should be better. It won't matter, haswell has amazing decode bandwidth.doug65536

1 Answers

8
votes

The primary point of assembly language is that what you write translates directly to individual machine instructions. Nearly all optimization is up to you, the programmer.

An assembler only does a very small number of optimizations that are mostly pretty trivial in any case. The primary one is that x86 processors have short jumps, near jumps and far jumps. Most assemblers can/will optimize a jump to use the smallest form of jump instruction that will get from the source to the destination address. Even when/if that isn't done automatically, 1) it rarely makes a significant difference in speed (even at the level of counting individual clock cycles), and 2) you can normally add short or near to the instruction to get the smaller size (and the assembler will give you a warning if that won't "reach").

Bottom line: optimization is rarely a much of a reason to choose one assembler over another. Real reasons are support for the instruction set(s) you care about and the platform(s) you want to target.