Assembler Reformatter

This tool can help you reformat your Assembler source code, independent of target CPU and can be embedded into several Editors such as Ultraedit and vi. It is available both in C-Sourcecode and a Binary version for Win32 platforms but can be recompiled for any other platform that supports C code.

Objective

Every developer working with Assembler, regardless of the CPU type that he is programming for has been experiencing that keeping source code tidy can be a challenging task. Assembler programs nevertheless demand being written in a well readable structure so as not to increase the difficulty of another reader to understand them quickly.

Take, for example, this ugly but correct chunk of code:

 
dly:
    ldi  Temp,0b00000101  ; set prescaler to 1024
    out     TCCR0,Temp

    ldi    Temp,184 ; preset the counter for 72
    out TCNT0,Temp ; cycles till overflow

 in Temp,TIFR ; reset the overflow flag 
 sbr  Temp,(1<<TOV0)
 out TIFR,Temp
 

Although accepted by the assembler, the opcodes are not clearly identifiable, Comments are spread throughout the lines, labels are not obvious. Often this type of code uses tabulator characters to separate its columns. This creates a new problem as tabulator spacings tend to be interpreted differently between editors. If you are lucky, the tab spacing can be adjusted, if you are not, the editor developer has forgotten this feature.

What if, at the flick of a switch, the code could be made to look like this:

 
dly:
          ldi       Temp,0b00000101     ; set prescaler to 1024
          out       TCCR0,Temp

          ldi       Temp,184            ; preset the counter for 72
          out       TCNT0,Temp          ; cycles till overflow

          in        Temp,TIFR           ; reset the overflow flag 
          sbr       Temp,(1<<TOV0)
          out       TIFR,Temp
 

Unfortunately only few programs exist on the market to assist in tidying up Assembler source code and all of them are linked to certain CPU types. Most, if not all, assembler dialects though have one thing in common, which is a four column structure

Label          Op-Code        Operand            ; Comment

Out of which all elements are optional (with the exception of the operand that can not exist without op-code).

This little Assembler reformatter plugin now, which is written in C can work, independently of Operating System as a standalone command line module. If the editor allows such customization (like VI does in Unix or ULTRAEDIT does in Windows), this command line version can be embedded into the editor.

In Ultraedit, you can see the configuration details in the snapshot at the top of this article (make sure the name of the executable matches the one you have chosen or downloaded in the binary package):

The syntax of the command line version is quite straightforward:

asflt [-w nn] file1 [file2] [file3]…

The optional Argument –w allows setting the column width of the four individual columns which defaults to 10. The filenames passed as parameters are the assembler files to be reformatted.

How to Download

ASFLT21.C

Source Code
c, 9K, 08/19/09, 124 downloads

ASFLT21.exe

Win32 binary
exe, 24,3K, 08/19/09, 92 downloads