flat assembler
Message board for the users of flat assembler.
Index
> Main > [fasmg] 1f/1b type discardable labels? |
Author |
|
revolution 22 Sep 2016, 14:05
Use the dot (.):
Code: function: ;..; .loop: ;<--- make a label named function.loop ;... jnz .loop ;branch to label named function.loop |
|||
22 Sep 2016, 14:05 |
|
revolution 22 Sep 2016, 14:08
Oh, I missed the second question. for temporary forward and backward labels use @@, @f and @b:
Code: @@: jmp @f jmp @b @@: |
|||
22 Sep 2016, 14:08 |
|
Tomasz Grysztar 22 Sep 2016, 14:39
A simple macro that implements @@/@f/@b into fasmg is in the "Basic macros for fasmg" thread.
The same mechanic can be used to implement more levels (like @f1, @f2, etc.), or a separate sets of symbols could be created in parallel. PS The name '1f' cannot be used for a symbol name, because it is a number, a floating-point one, to be exact. |
|||
22 Sep 2016, 14:39 |
|
Akeo 22 Sep 2016, 15:15
Aha, so that's called an "anonymous label". I guess I should have checked the basic macros thread first.
Thanks for the replies! |
|||
22 Sep 2016, 15:15 |
|
Tomasz Grysztar 22 Sep 2016, 15:22
I'm going to present two possible ways of extending these basic macros. The fact that there are many "competing standards" (and that over the years people used to ask for various variants for fasm) was the main reason why I decided to leave it up to macros. And for non-tool-generated source codes the namespaces (like what revolution proposed in his first post) are in my opinion superior.
First method is to keep anonymous labels always named @@, but to allow jumping not only to the nearest ones with @b and @f, but also a bit further - for example @b2 and @f2 would to a second one in given direction. My sample defines it only up to @b3/@f3, and these definitions could be automated with "repeat" loop, but I kept it this simple so it is easier to visually parse what it does: Code: define @f @f1 define @ff @f2 define @b @b1 define @bb @b2 macro @@ tail match label, @f1? label tail end match local anonymous @b3? reequ @b2 @b2? reequ @b1 @b1? reequ @f1 @f1? reequ @f2 @f2? reequ @f3 @f3? reequ anonymous end macro struc dummy end struc repeat 3 @@ dummy end repeat purge dummy Code: jmp @f2 ; -> 2 @@: ; 1 jmp @b ; -> 1 jmp @f2 ; -> 3 @@: ; 2 jmp @b2 ; -> 1 @@: ; 3 jmp @b3 ; -> 1 The second variant allows to define multiple labels called @1, multiple ones called @2, etc. This time it @1f to jump to the nearest @1 forward, @1b to jump to the nearest @2 backward, and so on. The number of available label names can be tweaked by modifying the first line only: Code: repeat 10 macro @#% tail match label, @#%#f? label tail @#%#b? equ @#%#f? end match local anonymous @#%#f? equ anonymous end macro define @#%#f? @#% end repeat Code: @1: ; a jmp @1f ; -> b jmp @2f ; -> c jmp @1b ; -> a @1: ; b jmp @1b ; -> b @2: ; c jmp @2b ; -> c @1: ; d jmp @1b ; -> d |
|||
22 Sep 2016, 15:22 |
|
Akeo 23 Sep 2016, 10:41
That second variant is pretty much exactly what I was looking for, so that's what I went with.
Thanks, as usual, for the awesome help! |
|||
23 Sep 2016, 10:41 |
|
VEG 07 May 2017, 18:52
I have another idea of anonymous labels. We have numbered labels from @0 to @9. When we at @0, it means that we can jump only forward to @1 .. @9. When we at @5, we can jump backward to @0 .. @5, or forward to @6 .. @9. When we at @9, we can jump backward only (because there is no @10).
Basically, the idea is: Code: ; it is possible to jump (only): @0: ; backward to @0, forward to @1 .. @9 @1: ; backward to @0 .. @1, forward to @2 .. @9 @2: ; backward to @0 .. @2, forward to @3 .. @9 @3: ; backward to @0 .. @3, forward to @4 .. @9 @4: ; backward to @0 .. @4, forward to @5 .. @9 @5: ; backward to @0 .. @5, forward to @6 .. @9 @6: ; backward to @0 .. @6, forward to @7 .. @9 @7: ; backward to @0 .. @7, forward to @8 .. @9 @8: ; backward to @0 .. @8, forward to @9 @9: ; backward to @0 .. @9, no forward labels @0: ; backward to @0, forward to @1 .. @9 @1: ; backward to @0 .. @1, forward to @2 .. @9 @2: ; backward to @0 .. @2, forward to @3 .. @9 @3: ; backward to @0 .. @3, forward to @4 .. @9 ... Code: @0: ; @0 removes old labels @1 .. @9, so we can jump only forward here test eax, eax jz @5 @1: ; at this point we can jump backward to @0 or @1, or forward to @5 or @9 mov eax, 500 jmp @9 @5: ; at this point we can jump backward to @0, @1 or @5, or forward to @9 mov eax, 100 @9: ; here we can jump only backward to @0, @1, @5 or @9 @0: ; here we can jump only forward to following @0 .. @9 ... The problem is here that it requires using macros @0 .. @9, and the same name required for "equ"s. I've tried to write an experimental macro which will use the same name for a macro and for a "label". It seems that it works nice with "define": Code: macro @0 tail if defined @0 redefine @0 2 else define @0 1 end if end macro @0: db @0 @0: db @0 Code: macro @0 tail @0 equ 1 end macro @0: db @0 @0: db @0 Maybe it is better to allow to use "equ" in the same way as "define", like: Code: define @0 1 equ @0 1 It seems that this difference in syntax was dictated by the FASM1. IMHO, it is better to use similar syntax for similar tasks. It seems that it is possible to extend syntax of the define itself for supporting of the equ behavior. For example, "define!" may work like the equ And yes, do you think that this idea is ok, or maybe it is better to refuse it, because it is not ok to use the same name for a macro and for an equ? Last edited by VEG on 07 May 2017, 19:10; edited 1 time in total |
|||
07 May 2017, 18:52 |
|
Tomasz Grysztar 07 May 2017, 19:09
VEG wrote: But I need to set @0 to an anonymous label, and I have to use "equ" for it, but I can't VEG wrote: Maybe it is better to allow to use "equ" in the same way as "define", like: Code: macro equ? statement& rawmatch name= raw_value, statement match value, raw_value define name value else define name end match else define statement end rawmatch end macro |
|||
07 May 2017, 19:09 |
|
VEG 07 May 2017, 19:21
Tomasz Grysztar, it works, thank you
|
|||
07 May 2017, 19:21 |
|
VEG 07 May 2017, 21:27
I've modified my first idea a bit. Every @@ resets @0..@9. So, there are own @0..@9 between @@ and @@, like local anonymous sublabels. @b and @f are still available, and they point to the nearest @@ labels as always before.
Code: macro @@ tail match label, @f? label tail @b? equ @f? end match local anonymous @f? equ anonymous repeat 10, i:0 local anonymous#i redefine @#i anonymous#i end repeat end macro define @f? @@ repeat 10, i:0 macro @#i tail match label, @#i label tail end match end macro end repeat Code: ; This example outputs these bytes, as expected: 1,2,3,4,4,6,7,8,9. @@: db @1 @1: db @2 @2: db @f @@: db @b @1: db @2 @2: db @f @@: db @1 @1: db @2 @2: db @3 @3: I've written it (based on the example by Tomasz Grysztar), it works, but I don't know how This part of FASM macros is still pure magic for me. For example, I thought that equ will be required here, but it works only with redefine (redefine @#i anonymous#i) =) I'll try to read the FASM Manual again. Maybe I'll understand it better. Last edited by VEG on 07 May 2017, 21:44; edited 1 time in total |
|||
07 May 2017, 21:27 |
|
Tomasz Grysztar 07 May 2017, 21:38
VEG wrote: I've written it (based on the example by Tomasz Grysztar), it works, but I don't know how This part of FASM macros is still pure magic for me. For example, I thought that equ will be required here, but it works only with redefine (redefine @#i anonymous#i) =) I'll try to read the FASM Manual again. Maybe I'll understand it better. |
|||
07 May 2017, 21:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.