AsmHighlighter Part II : Automatic x86 asm instruction size evaluation
This blog post was originally posted on my previous blog code4kFollowing the previous post about AsmHighlighter, I have just released a new version 1.1 of AsmHighlighter that evaluates x86 ASM instruction size for each instructions in your code. The instruction size is inserted in the comment next to the instruction.
When you are coding 4k or 64k (partially) demos in x86 assembler with size optimization in mind, it's sometimes useful to check the instruction size (as it is sometimes not so obvious, x86 has a lot of weird rules for their instruction size, particularly when using eax register on source/destination, or using ebx without an offset...etc).
This feature is available when you perform a formating of your document (Menu Edit/Advanced/Format document or selection, or Ctrl+k, Ctrl+d). Here is a screenshot result:
The magic behind it is that i have discovered a cool managed library called : Fasm Managed from Shynd's. This is a managed .NET dll that can perform dynamic x86 ASM compilation inside a .NET application. The code is simple as below:
byte buffer = ManagedFasm.Assemble("mov eax, 0");
Thanks to this great module, it was quite easy to integrate a fast evaluation of a x86 instruction size, although this evaluation is done at the line level, so the evaluation doesn't have any information on labels, defines...etc. But i have integrated a simple (but not perfect) workaround. Also, because this library is using FASM as a compiler, i had to perform some "normalization" on the code (that is mainly targeting MASM syntax), but it's working quite well!
With this instruction size feature, AsmHighlighter is becoming a bit more related to 4k-64k intros coding! ;)