Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnu Assembler (GAS) Optimizations

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!

like image 822
Adrian Avatar asked Feb 22 '26 13:02

Adrian


1 Answers

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 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.

like image 72
Jerry Coffin Avatar answered Feb 24 '26 09:02

Jerry Coffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!