News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Cleanning asm files

Started by Grincheux, January 09, 2016, 06:00:50 AM

Previous topic - Next topic

Grincheux

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%.

ragdog

QuoteCleanning asm files

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

And remove the code? :biggrin:

qWord

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
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

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

Grincheux

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.

Grincheux

The problem was that there is no CRLF on the last line.
Corrected, new version attached.

ragdog

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.

Grincheux

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 or download the source files

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


jj2007

Still little problems with quotes:
.elseif al=="
...
.if al!="
...
.Until al=="
...
.Break .if byte ptr [LineBuf+eax]=="

guga

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


Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Grincheux

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.

qWord

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.
MREAL macros - when you need floating point arithmetic while assembling!

ragdog

This is always Tabs vs Spaces discusion :biggrin:
Is only a taste thing.
I use tabs size 4

Grincheux


jj2007

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)