The MASM Forum

General => The Campus => Topic started by: Grincheux on January 09, 2016, 06:00:50 AM

Title: Cleanning asm files
Post by: Grincheux on January 09, 2016, 06:00:50 AM
Sometimes for uploading sources files they are too bigs and we can't upload them.
I created this utility to remove all the thing we don't need in a source files.
For example it deletes unwanted tabs or spaces (except in the strings).
It replace CRLF by a line feed.
It removes trailing spaces.
The files I have tested have been reduced by 50%.
Title: Re: Cleanning asm files
Post by: ragdog on January 09, 2016, 06:53:38 AM
QuoteCleanning asm files

It replace CRLF by a line feed.
It removes trailing spaces.

And remove the code? :biggrin:
Title: Re: Cleanning asm files
Post by: qWord on January 09, 2016, 07:06:08 AM
Quote from: Grincheux on January 09, 2016, 06:00:50 AM
I created this utility to remove all the thing we don't need in a source files.
formatting and comments ...  :icon_confused:

BTW: WS_BORDER+WS_CAPTION+WS_OVERLAPPED+WS_SYSMENU+WS_VISIBLE != WS_BORDER OR WS_CAPTION OR WS_OVERLAPPED OR WS_SYSMENU OR WS_VISIBLE
Title: Re: Cleanning asm files
Post by: jj2007 on January 09, 2016, 08:30:35 AM
Hi Philippe,

Attached a file that has a problem around line 1170: it fails with an exception (esi is a bad pointer) in LireUneLigne.

Probably it's only a counter problem: the file has only 607 lines...

Good luck,
Jochen
Title: Re: Cleanning asm files
Post by: Grincheux on January 09, 2016, 04:12:48 PM
I am correcting. With all my asm files no problems, with yours and those in Masm32 folder it crashes! The program crashes after the last input line! Generaly the number of lines is divided by 2.
Title: Re: Cleanning asm files
Post by: Grincheux on January 09, 2016, 05:16:01 PM
The problem was that there is no CRLF on the last line.
Corrected, new version attached.
Title: Re: Cleanning asm files
Post by: ragdog on January 09, 2016, 06:56:21 PM
Hello Philippe

Why removes you trailing spaces?

A good tool is replace tabs with spaces.
I use by coding tabs, but i post my code other users hate tabs and a tool to replaced would be good.
Title: Re: Cleanning asm files
Post by: Grincheux on January 09, 2016, 09:03:08 PM
Trailing spaces are not useful.
I also use tabs rather than spaces.
The program replaces tabs by one space. 1 space = 1 tab.
Try the program, Download Binary (http://www.phrio.biz/download/CleanAsm.exe) or download the source files (http://www.phrio.biz/download/$CleanAsm.exe)

I made tests on windows.inc (masm32/include folder) once I pass to the program I lost 200kb!
I do not remove multi-lines comments.

Spaces are removed if the character after the space is :

cmp ah,','
je @SkeepSpace
cmp ah,':'
je @SkeepSpace
cmp ah,'+'
je @SkeepSpace
cmp ah,'-'
je @SkeepSpace
cmp ah,'*'
je @SkeepSpace
cmp ah,'/'
je @SkeepSpace
cmp ah,'['
je @SkeepSpace
cmp ah,'['
je @SkeepSpace
cmp ah,'='
je @SkeepSpace
cmp ah,'%'
je @SkeepSpace
cmp ah,'<'
je @SkeepSpace
cmp ah,'>'
je @SkeepSpace
cmp ah,'"'
je @SkeepSpace
cmp ah,'|'
je @SkeepSpace
cmp ah,'&'
je @SkeepSpace

Title: Re: Cleanning asm files
Post by: jj2007 on January 10, 2016, 02:31:18 AM
Still little problems with quotes:
.elseif al=="
...
.if al!="
...
.Until al=="
...
.Break .if byte ptr [LineBuf+eax]=="
Title: Re: Cleanning asm files
Post by: guga on January 10, 2016, 03:10:03 AM
I agree with Removing trailing spaces but, exchanging spaces by tabs don´t.

Personally i don´t like using tabs inside my code. It leads to lack of readability when i want to see it without a editor, i mean, in notepad, for example. I don´t remember how Radasm handle this, but in RosAsm you can use tabs while you are writing but they are immediately replaced by 4 spaces (or 2, 4, 8 as defined by the user). Same for line feed...Why using a single line feed, instead a regular paragraph (caret+line feed)?

About removing comments...well..It all depends of your needs. Comments are necessary to understand what exactly the code is doing (Not only for a beginner, but for experienced programmers too). So, removing comments (single or multi-lines should be a option, IMHO)

It could be a good thing if you try to "beautifier" the code. I mean, make them show as a regular tree. Removing extra spaces at the beginning or in the middle of instructions. On the beginning, make them be displayed on a multiple of 4 and in between register and variables etc, be just 1 space.


    If eax 0 ; 4 spaces at the begining. 1 space in between the operations. No traling space at the end
         mov eax 7 ; 8 spaces. 1 space in between the operations. No traling space at the end
    End_If ; 4 spaces. 1 space in between the operations. No traling space at the end


The multiple of 4 spaces at the beginning is just a hint. It can be 8, 6 etc...It will depend on the editor peiople are using. In Rosasm 4 spaces to replace a tab is good enough. In Radasm or quickeditor i guess uses tabs, but, the amount of how they are displaced can be the same for the spaces above. Like:


    If eax 0 ; 1 Tab at the begining. 1 space in between the operations. No traling space at the end
         mov eax 7 ; 2 Tabs. 1 space in between the operations. No traling space at the end
    End_If ; 1 Tab. 1 space in between the operations. No traling space at the end


Title: Re: Cleanning asm files
Post by: Grincheux on January 10, 2016, 03:31:00 AM
I am trying to write a kind of interpreter, and I need to clean the input code. I wrote this as a routine of the main code and after I told that this part could be useful to programmers. It is not for saving a source but for transferring it minimizing the data size to send. For example, here we are limited to 512kb. It was my idea when I create this utility. I choose the space as a separator, it's a choice. When I write my source file I use tabs. Download the source file of this program to understand how I write.
Title: Re: Cleanning asm files
Post by: qWord on January 10, 2016, 03:40:58 AM
Quote from: Grincheux on January 10, 2016, 03:31:00 AMIt is not for saving a source but for transferring it minimizing the data size to send. For example, here we are limited to 512kb.
The plain source code is commonly not the problem (512KB, compressed!), but rather other resources associated with the program, e.g. images /icons.
Title: Re: Cleanning asm files
Post by: ragdog on January 10, 2016, 04:00:42 AM
This is always Tabs vs Spaces discusion :biggrin:
Is only a taste thing.
I use tabs size 4
Title: Re: Cleanning asm files
Post by: Grincheux on January 10, 2016, 04:49:55 AM
me too (tabs=4)
Title: Re: Cleanning asm files
Post by: jj2007 on January 10, 2016, 05:30:21 AM
Quote from: guga on January 10, 2016, 03:10:03 AMIt could be a good thing if you try to "beautify" the code. I mean, make them show as a regular tree. Removing extra spaces at the beginning or in the middle of instructions.

Before:
@ClearLine_Quote :

mov Byte Ptr [ebx],al

inc edx
inc ebx

@ClearLine_Quote_Loop :

mov al,Byte Ptr [edx]

test al,al
jz @ClearLine_End

mov Byte Ptr [ebx],al

inc edx
inc ebx

cmp al,cl
jne @ClearLine_Quote_Loop

mov ah,cl
jmp @ClearLine_Loop


After:
@ClearLine_Quote :

mov Byte Ptr [ebx],al

inc edx
inc ebx

@ClearLine_Quote_Loop :

mov al,Byte Ptr [edx]

test al,al
jz @ClearLine_End

mov Byte Ptr [ebx],al

inc edx
inc ebx

cmp al,cl
jne @ClearLine_Quote_Loop

mov ah,cl
jmp @ClearLine_Loop


This is RichMasm's AutoFormat function, far from being perfect. And personal taste plays a big role, of course...

For example, what I definitely hate is this style:

      mov                              eax,123
      add                              eax,100
      sub                              eax,ecx
      inc                              eax


The eye is forced to jump from extreme left to extreme right, every now and then losing the line etc... a nightmare for me, and yet there are many coders who seem to love this style 8)
Title: Re: Cleanning asm files
Post by: guga on January 10, 2016, 05:57:07 AM
Quote from: JochenThe eye is forced to jump from extreme left to extreme right, every now and then losing the line etc... a nightmare for me, and yet there are many coders who seem to love this style 8)

Me too. It is extremely hard to follow. But, it has worst :icon_mrgreen: Try reading a source with 1 Mb containing everything at the beginning of the line without paragraphs, such as (including comments):

Main:
xor eax eax
cmp eax 5
je L5>
shl eax 3
.....


Easy for a few lines, but on big sources..OUCH ! :icon_mrgreen:
Title: Re: Cleanning asm files
Post by: Grincheux on January 10, 2016, 12:16:45 PM
When I began to program, we had no computer, we had to write on a paper and respect the columns. Cobol language... That is certainly for this reason... Later i program in fortran, same thing... remember format, comments, varialbles beguinning by I...
Title: Re: Cleanning asm files
Post by: Grincheux on January 10, 2016, 02:07:23 PM
If you want I have a new version without the bug found in scancode.asm from masm32 examples.

Binary (http://www.phrio.biz/download/CleanAsm.exe)
Source & Binary (http://www.phrio.biz/download/$CleanAsm.exe)

You can find a line like this one :

Quoteinclude\masm32\include\masm32rt.inc

It is not an error the syntax is accepted by Masm

Here are some stats :

Quote
ProcVariants SFX.exe........= 190Kb
ProcVariants.asm.exe........= 189Kb
ProcVariants.asm.............= 12Kb (Original file)
ProcVariants.asm.txt.........= 8Kb (Modified by CleanAsm.exe)
ProcVariants.zip...............= 4Kb
ProcVariants.asm.txt.7z.....= 3Kb
ProcVariants.asm.zip.........= 3Kb