flat assembler
Message board for the users of flat assembler.

Index > Main > How to indent?

Author
Thread Post new topic Reply to topic
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 13 Feb 2005, 14:45
My problem is how you indent your sourcecodes. I tried many patterns, but I always find something that I don't like, and change it again and again. I already used the pattern in which I use tab (meaning 8 spaces) every time I make more inner loop, like this:
Code:
mov     eax,ebx

.inner_loop:
        mov     eax,ebx
        mov     eax,ebx

        .another_inner_loop:
                mov     eax,ebx
                mov     eax,ebx
                cmp     eax,ebx
                jz      .first_level
                cmp     eax,edx
                jz      .more_inner_level

                .more_inner_level:
                        mov     eax,ebx
                        mov     eax,ebx
.first_level:
        mov     eax,ebx
    

I alos tried like it is in fasm sourcecodes:
Code:
main_label:
        mov     eax,ebx
        mov     eax,ebx
      another_label:
        mov     eax,ebx
        mov     eax,ebx
      this_is_also_label:
        mov     eax,ebx

next_big_label:
        mov     eax,ebx
    

But both these don't satisfy me at 100%. I sometime got stuck in my own sourcecode even though. So my question is: what method have you found to indent your code, so that it is readable, and look great?
Post 13 Feb 2005, 14:45
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 13 Feb 2005, 15:24
IMHO, horizontal indentation in assembly code is not usefull at all. Assembly language have different syntax than HLLs and formating rules are different too.
The problem with horizontal indentation is that it prevents proper recognition of source elements: label, opcode, operands, comment
Better use vertical indentation (i.e. empty lines between logical blocks) and more comments.
Using local labels (.localLabel) and reasonable names of labels will help make code more readable.

Horizontal indentation is usefull only for complex nested data definition statements, especially using macroses and in FASM, in macro definitions, where the rules are more HLL-like.

Regards.
Post 13 Feb 2005, 15:24
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 13 Feb 2005, 16:12
I like indenting especially for complex looping. and you can use the if.inc macros which greatly reduces "Label HELL", both of these methods used together make for some pleasurable assembly programming, AND debugging. For and example you can look at my code in windows forum, look for the question, 'problems with windows menus' and download the source code.
MadMatt
Post 13 Feb 2005, 16:12
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 14 Feb 2005, 02:11
just like JohnFOund told, my code looks like:
Code:
;if something then skip loop
cmp [skiploop],0
je .endloop

;otherwise fill variables for loop
mov cx,[outerloopcount]

;outer loop until ecx>0
.outerloop:
dec cx
cmp cx,0
je .endloop

;inner loop - write 'a' ecx times
mov eax,ecx
mov ah,2
mov dl,'a'
.innerloop:
int 21h
dec eax
cmp eax,0
ja .innerloop

;continue looping
jmp .outerloop
.endloop:
    

hope you got it
Post 14 Feb 2005, 02:11
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 14 Feb 2005, 15:40
I feel that well, soon be debatng who is right about K&R/"One true brace style", GNU style, etc,etcetc ad nausem

once and for all:
There is no right and wrong with indentation
it's just a matter of personal preference and stubborness
Razz

anyone else trying to say something else if just trying to convince you to use his/hers indentation preference, I frequenlty point out that my preference is K&R and that I'm always right and every one else is wrong Wink (j/k, pun intended)

Some times indentation is good, eg, when you got nested loops, it helps to show their "level" by indentation (can be a space, a tab, a bilion spaces and tabs,etc). And some times it's easier to "put it all on one line" - eg: marco three_nop { db 90h,90h,90h }
Post 14 Feb 2005, 15:40
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.