Code Alignment ....
I first didn't think of implementing any Align feature for code as this seemed to me an 'out of purpose' idea. But some other programmers told me that it was an absolute must have in an assembler. So, here it is:
align 16 ; (decimal only parameter)
>>> inserts the needed number of NOPs to reach the desired boundary.
If the NOPs number is greater than 4, the two first NOPs are replaced by a short JMP.
Intel documentation gives only two cases for using Alignment:
A loop entry label should be 16-byte aligned when it is less than 8 bytes away from that boundary.
A label that follows an unconditional branch or function call should be 16-bytes aligned when it is less than 8 bytes away from that boundary.
I implemented this because of the aforementioned advice, but I am not yet fully convinced it is a good idea. About optimization, I am of the opinion that:
Optimization for one processor is not always true for another one.
Optimization for yesterdays Intel processors is not the one for today and much more so is not the one for tomorrow.
Optimization, today, is far too sophisticated to be considered in the real world, even if it works fine on some scholastic examples and if some champions insist on using it every day.
Processors are now blazing fast and clean assembler writing is enough.
If not, rewrite the code.
Optimizing assembler code while, at the same time, other programmers write entire systems or sound routines in C, is indeed a laughing matter.
The better code optimization is 'the code we do not write' ; I mean that a clean short and intelligent routine is always much faster than a dirty, stupid long one.
~~~~~~~