flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [solved].if .elseif etc for bit/flags testing

Author
Thread Post new topic Reply to topic
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 19 Sep 2022, 14:12
Hi
I'm trying to manage some .if macros for some purpose but something wrong.
Code:
macro purgeif
{
        purge .else,.endif
}
macro .if arg
{       local elseiflabel
        test    rax,arg
        jz              elseiflabel
        macro .else
        \{      local endiflabel
                jmp             endiflabel
                elseiflabel = $
                elseiflabel equ endiflabel
        \}
        macro .endif
        \{      elseiflabel = $
                purgeif
        \}
}


mov rax,1
.if 2
        mov rax,13
.else                       ;<-- error
        .if 1
                mov rax,111
        .endif
        .if 2
                mov rax,222
        .endif
.endif
    

jmp endiflabel
processed: jmp endiflabel?0x6
error: undefined symbol 'endiflabel?0x6'.


Last edited by Overclick on 20 Sep 2022, 04:21; edited 2 times in total
Post 19 Sep 2022, 14:12
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 19 Sep 2022, 14:21
elseiflabel is defined twice. I assume the second definition is supposed to be endiflabel?
Post 19 Sep 2022, 14:21
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 19 Sep 2022, 14:25
Quote:

elseiflabel is defined twice. I assume the second definition is supposed to be endiflabel?

elseiflabel equ endiflabel
Post 19 Sep 2022, 14:25
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 19 Sep 2022, 14:28
I use here principle that used before at @@@ macro
Code:
macro @@@ t& {
        local anonymous
        @F1=$
        @B5 equ @B4
    @B4 equ @B3
    @B3 equ @B2
    @B2 equ @B1
    @B1 equ @F1
    @F1 equ @F2
    @F2 equ @F3
    @F3 equ @F4
    @F4 equ @F5
    @F5 equ anonymous
    match =: arg,t \{ arg \} }    
Post 19 Sep 2022, 14:28
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 19 Sep 2022, 15:58
Ok, solved
Code:
macro .if arg
{       local temp1,temp2
        elseiflabel equ temp1
        endiflabel equ temp2
        test    rax,arg
        if defined elseiflabel
                jz              elseiflabel
        else
                jz              endiflabel
        end if
        macro .else
        \{      jmp             endiflabel
                elseiflabel = $
        \}
        macro .endif
        \{      endiflabel = $
                restore elseiflabel,endiflabel
                purge .else,.endif
        \}
}    
Post 19 Sep 2022, 15:58
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 20 Sep 2022, 04:20
Update:
Code:
macro .if arg
{       local temp1,temp2,temp3
        elseiflabel     equ temp1
        elselabel       equ temp2
        newendiflabel equ endiflabel
        endiflabel      equ temp3
        test    [CurrentTesting],arg
        if defined elseiflabel
                jz              elseiflabel
        else if defined elselabel
                jz              elselabel
        else
                jz              endiflabel
        end if
        macro .elseif arg
        \{      jmp             newendiflabel
                elseiflabel = $
                restore elselabel,elseiflabel,endiflabel
                purge .elseif,.else,.endif
                .if arg
        \}
        macro .else
        \{      jmp             endiflabel
                elselabel = $
        \}
        macro .endif
        \{      
                endiflabel = $
                restore elseiflabel,elselabel,endiflabel
                purge .elseif,.else,.endif
        \}
}    

I made it for bits/flags testing in my render engine. Looks cool, isn't it? )


Description:
Filesize: 33.41 KB
Viewed: 2484 Time(s)

Capture.PNG


Post 20 Sep 2022, 04:20
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.