just a few lines for talking about a typical assembly optimization which is usually encountered during reversing: the divisions.
the reason behind the existence of such optimizations is that the divisions (div/idiv) take many cpu cycles and so this is a way for saving some nanoseconds at the price of a not easily readable assembly code (which affects only who reverses it).
take the following 2 examples:
Code:
B8 79 78 78 78 MOV EAX,78787879
F7 E9 IMUL ECX
C1 FA 03 SAR EDX,3
Code:
B8 79 78 78 78 MOV EAX,78787879
F7 E9 IMUL ECX
C1 FA 03 SAR EDX,3
8B C2 MOV EAX,EDX
C1 E8 1F SHR EAX,1F
03 C2 ADD EAX,EDX
8B D0 MOV EDX,EAX
C1 E2 04 SHL EDX,4
03 D0 ADD EDX,EAX
the first one is a simple "eax / 17" (division by 17) and the second is "eax % 17" (modulo 17), nice eh? :)
if someone wants to go deeper in this thing I suggest the Agner's document
http://www.agner.org/optimize/optimizing_assembly.pdf in the section "Integer division by a constant".