I've been programming in assembly (mainly nasm) for quite some time.. after some point I have realized that I have been overdoing some of the optimizations to a point where the code became more difficult to understand without comments.
Finally I have overlooked what I have done, and found that a lot of my optimizations could have been automated. However I don't know how to do it.
For example, optimized inline functions. If the following is the only code of a program:
Code: Select all
start:
mov eax, 2
call SuperFunction
int 0x20
SuperFunction:
push ebx
mov ebx, 3
add ebx, eax
mov [0x700], ebx
pop ebx
ret
Code: Select all
start:
mov eax, 2
push ebx
mov ebx, 3
add ebx, eax
mov [0x700], ebx
pop ebx
int 0x20
Code: Select all
start:
mov eax, 2 ; This is still needed because it may be used by the software interrupt.
; (It would be nice to be able to tell the assembler whether it's needed it not.)
mov dword [0x700], 5
int 0x20
Code: Select all
nasm file.asm -O3
Code: Select all
fasm file.asm
Usually hear something like... "Oh, that's simple - just use a macro." ...well, I don't know about you, but I have no idea how to make a macro make the optimization I made, without making a whole bunch of extremely specialized macros.
Some of you may say that I should change the "SuperFunction" function to a macro. That would make it inlined, however that would force me to rewrite it into a function if I need to call it more than once. Additionally, by that time I could get confused, why is it a macro in the first place?
So, does anybody know of a way to get this thing to work? Some good assembler capable of optimizing well? I think it would save me, and a lot of other people some effort.
Plus, there is an additional problem:
Imagine you have a super duper assembler that is capable of doing the optimizations that I noted above.
Now you don't want to "%include" everything into your main file because that would make all public AND private functions accessible - This may cause you to have longer function names because you don't want to have conflicts between two same named functions... So instead, you link everything together.
Unfortunately, the linker usually doesn't seem optimize assembly code. I don't know if it can do inline functions either. Using the above example, if "SuperFunction" is assembled in a separate file, I am not sure how it would be possible for this stuff to be optimized much at all.
So the solution is to either get a better linker, or have the super duper assember have abilities to have private and public functions.
Does anybody know of any assemblers that can do such an optimization? Once again, I think it would help a LOT of people who write in assembly...
Thank you,
Veniamin
PS - I realize that for some of the optimizations, we go by some assumptions of what we will not be doing in assembly... well, I think that by now it is safe to say that we will not be programming self modifying code. That should cover all of the worries.. If we are programming self modifying code, then possibly we could flag to the assembler not to optimize some piece of code... however I believe that such instances would be rare.