flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > suggestion: anonymous label extension

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
hey Tomasz, for common lib-like procedures i make for myself i prefer to use only anonymous labels ('@@') as to not conflict with any of the code in whatever project i am making, but sometimes i need to jump past the nearest next anonymous label, and then i cannot use jmp @f/jmp @b

eg:

Code:
@@:
   jmp ok

@@:

ok:
    


i would like 'ok' to still be an anonymous label, but have the ability to jump to it, so i was wondering if you could extend the anonymous label feature of fasm to allow to specify how many anonymous labels forward/back when needed (if fasm already has this i am sorry), i do not care about how the syntax would be

sorry if my suggestion is poor, but its something i would use is every project

ps: i really should get a thesaurus, i used 'anonymous' way too many times Smile

_________________
redghost.ca
Post 26 Jan 2006, 02:25
View user's profile Send private message AIM Address MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
i was also pushing Tomasz to allow also @ff (second anoymous label forward) and @bb. It would be very useful in small if-else constructs, where i everytime have to think about label name. And in some cases such constructs are inavoidable even when coing asm-style.
Post 26 Jan 2006, 11:50
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
Inavoidable? I would recommend not using anonymous labels at all!

I will consider adding support for things like @ff or @bbb, but I'm still a bit afraid of them being overused.
Post 26 Jan 2006, 12:38
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
I didn't say aninymous labels are inavoidable, i said small if-else constructs are inavoidable. For example this from FASMLIB:
Code:
        ;push share mode depending on [.mode]
        cmp     [.mode], 0      ;read
        jne     @f
        push    1               ;FILE_SHARE_READ
        jmp     .sharemode_done
@@:     push    0
.sharemode_done:    

What this block code does is clear from comment (or from preceding label in your style of "commenting"), and reader usually doesn't need to look how is it done (only what is done). So I think it generally doesn't decrease readability if you have it this way (but saves you from thinking about new names):
Code:
;push share mode depending on [.mode]
        cmp     [.mode], 0      ;read
        jne     @f
        push    1               ;FILE_SHARE_READ
        jmp     @ff
@@:     push    0
@@:    

Block is so small that scoping where @ff is no problem, and when acting outside such small block anonymous labels really shouldn't be used.

Quote:
I would recommend not using anonymous labels at all!
Hmm, in you style maybe not, but when you have block of code which is described in comment before it, and you need some conditional-jump-over-something inside that code, then labels messes it a little.

Of course it will be overused, but as i said some time ago, if somebody doesn't know how to write readable code, any restricting him from doing so wouldn't help. It is like OOP, which forces you to write "proper" code, at cost of possibilities.

btw, @ff and @bb are pretty enough, i can't imagine small "block" (explainable with simple-sentence comment) which would require 3 levels. And this if-else is only thing where i need 2, otherwise 1 is enough.
Post 26 Jan 2006, 15:35
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
I like to use very short labels like ".a", ".b" etc. instead of local labels. I find that is very clear about where the code goes. So using your example it would look similar to this:
Code:
        cmp     [.mode], 0      ;read
        jne     .a
        push    1               ;FILE_SHARE_READ
        jmp     .b
.a:     push    0
.b:    
Post 26 Jan 2006, 15:54
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
revolution: this won't work very well in bigger procs. Image you have some 200 lines with such labelling, and then you want add something to the middle. You must get at the end of proc to look which letter to continue, or try some two-letters, whch may or may be not used elsewhere etc. It's somewhat non-systematic, which means it can work nice with small codes, but surely not in bigger.
Post 26 Jan 2006, 16:38
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
But when you want to insert some new anonymous label in the middle of proc that is already using anonymous labels, it's even worse than that.
Post 26 Jan 2006, 17:03
View user's profile Send private message Visit poster's website Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
I vote for implementing @ff- and @bb-like naming support... that would be a nice addition to fasm..
Post 26 Jan 2006, 17:12
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
But if I implement just @ff and @bb as vid proposes, I bet people will soon start to ask why @fff is not allowed. Wink
Post 26 Jan 2006, 17:16
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
IMHO anonymous labels are good only in some places when they are relatively close to @f or @b symbols, for example here:

Code:
test    eax,eax    ; if eax contains NULL, then create new string
        jnz     @f
        stdcall StrNew
@@:    


In this snippet use of anonymous label is quite obvious: it is used for skipping some code (if skip is needed). I'm using them in such situations.

But, when symbols like @fff or @bbbb were allowed, and used extensively, reading code would require counting (!!) @@s in order to understand what's going on.

Have you ever seen any RosAsm code? It doesn't allow local names to be any identifier, but one from between 'A0'..'Z9' (or something like this). Belive me it is totally unreadable at first sight, despite it has similar opcodes. Of course I have nothing against RosAsm, but I wouldn't like fasm sources end like this Wink
Post 26 Jan 2006, 17:22
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
But when you want to insert some new anonymous label in the middle of proc that is already using anonymous labels, it's even worse than that.

I've shown you how i code. Code is divided to (mostly independent) blocks of code, each beginning with description of what that block does. So you most of time don't need to look at other code, only into block you are interested in. For me, the scope of anonymous labels will be only inside such block, for example if i need to skip 2 instructions. IT will never be used across such blocks.

And i never "insert" something into block, i either "edit" it or "divide" to two (independent) blocks and insert another one between them.

Quote:
But if I implement just @ff and @bb as vid proposes, I bet people will soon start to ask why @fff is not allowed.

Surely. Answer is: "because such complicated constructs, which such complicated branching, shouldn't be done with anonymous labels for readability of code".

btw, even most of times when you need @ff are too complicated to be suitable for it, but that if-else is exception, and i hate thinking how-to-name-that-label. In my coding style, labels should be used only to mark beginning of block, not inside it. This way i have two sorts of labels, one local-to-block, and one above-block.
Post 26 Jan 2006, 17:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Tomasz Grysztar wrote:
But if I implement just @ff and @bb as vid proposes, I bet people will soon start to ask why @fff is not allowed. Wink

ok, then just add @f3 meaning 3 labels forward, etc... i know, really bad idea Very Happy
Post 26 Jan 2006, 19:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Quote:
Image you have some 200 lines with such labelling, and then you want add something to the middle.
Well if I get to that stage then I would do this (below) for two reasons: 1. It is more optimised for the processor. 2. No need for so many confusing labels.
Code:
        xor     eax,eax
        cmp     [.mode], 0      ;read
        setz    al                ;eax=1 for read, eax=0 otherwise
        push    eax               ;FILE_SHARE_READ    
Post 27 Jan 2006, 00:42
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
The_Grey_Beast wrote:
ok, then just add @f3 meaning 3 labels forward, etc... i know, really bad idea Very Happy

as for a bad idea, thats along the lines of what im thinking Very Happy

currently like vid says, i would probably only need it for 'ff' or 'bb', but other cases going 2+ forward is a maybe

i don't think the code is any less readable TBH, mostly considering about 80% of the sub-labels (of a procedure style label) i make are anonymous unless i have to name it because of the current limitation, and the only person usually reading my code is me Smile

Tomasz Grysztar wrote:
But if I implement just @ff and @bb as vid proposes, I bet people will soon start to ask why @fff is not allowed. Wink

i also agree ff/bb would be a bad syntax, but if you can code a self compiling assembler in assembler from scratch, i believe you can think up a good syntax for this extension (i have faith, just check the angel in my sig Very Happy)

_________________
redghost.ca
Post 27 Jan 2006, 00:47
View user's profile Send private message AIM Address MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
revolution: but i need to think forward, i may want to add more modes. From my experiences using such non-straightforward codes leads to problem with editing code. At least you need to think longer what it does.
Post 27 Jan 2006, 09:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
actually, i proposed something like this before.
check this.
http://board.flatassembler.net/topic.php?t=2357

the nice about jmp @f and @b is you put a @@ and two of them could reffer to it.

the problem with .v1: .v2: .v3: and ... is, you need to (identify or check) on the number of that particular .v(x): in order for you to jmp.

for @@: you could access it easily like @f <- u know you would jmp to/back to the next/prev @@: (@@ is big and noticeable)

so. imho, jmp @fff <- actually wouldn't work or (user friendly) in long run.

we want the computer able to knows (exactly) where we want to jump. but the problem is, we wish to only give it like "jmp @f" and it knows how many deepth level it needs to jmp.

frankly speaking, i hate labeling. i hate to name variable, label, procedure coz it is not an easy task. i hardly satisfied with the names i gave to variable. wndH, winH, win.h, wnd.H, WND.h

i predict, the next gen of assembler/compiler would be so self-aware that it knows what users mean when they put jmp @@

sorry for long nag. just my hpov.
Post 27 Feb 2006, 04:03
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
i just lay down on bed and think again.

if assembler/compiler could so self-aware that it knows where to jmp... maybe u and i no need to code it anymore. lol.
Post 27 Feb 2006, 04:36
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
ok, i thought of this, (a stack based idea)
Code:
(0)##:
(1)@@:
        jmp @f (2)
        jmp @f (3)
        jmp @b (1)
        jmp @b (0)
        jmp @b (0)
(2)@@:
        @f
        jmp @f (4)
        @f
        jmp @f (6)
        jmp @o (0) <- original
(3)@@:
        @b @b
        jmp @b (1)
(4)@@:
        jmp @b (4)
        @f @f
        jmp @f (6) <- @f last at 6, wouldn't reach 7 coz 7 is ## (original point)
(5)@@:
(6)@@:

(7)##:
    
Post 27 Feb 2006, 04:45
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
vbVeryBeginner wrote:
ok, i thought of this, (a stack based idea)
Code:
(0)##:
(1)@@:
        jmp @f (2)
        jmp @f (3)
        jmp @b (1)
        jmp @b (0)
        jmp @b (0)
(2)@@:
        @f
        jmp @f (4)
        @f
        jmp @f (6)
        jmp @o (0) <- original
(3)@@:
        @b @b
        jmp @b (1)
(4)@@:
        jmp @b (4)
        @f @f
        jmp @f (6) <- @f last at 6, wouldn't reach 7 coz 7 is ## (original point)
(5)@@:
(6)@@:

(7)##:
    


might be a little hard to keep track of, but probably the best idea so far a preprocessor 'push/pop' with an invisible stack, i like it

_________________
redghost.ca
Post 27 Feb 2006, 06:20
View user's profile Send private message AIM Address MSN Messenger Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
i think at least one additional kind of anonimous label would be usefull (in kind of @@@/@@f/@@b as suggested in another thread): this will let easy implement if/then/else or case switching via jumps.
Post 27 Feb 2006, 12:06
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:  
Goto page 1, 2  Next

< 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.