flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasmg] Problem reading "byte" from "byte [imm]" in match

Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 02 May 2023, 22:41
Hi,

I'm creating a macro for arm64 under fasmg like:

Code:
load x2, byte [0x11223344]
    


which should generate something like:

Code:
db 0xff, 0xff, 0xff
db (2 shl 5) | 1     ; 2 from x2 and last "1" from "[b]byte[/b] [mem"]
    



This is the current macro that I have. Most of the work from is not mine!

Code:
macro load a*, type_mem

    local size
    local address
    
    size=1
    address=0

    match = type [mem_addr], type_mem
   
        if type eq 'byte'
            size = 1
        else if type eq 'word'
            size = 2
        else if type eq 'dword'
            size = 3
        else if type eq 'qword'
            size = 4
        else 
            err 'invalid address prefix'
        end if 

        address=mem_addr
   
    end match

    aarch64.parse_operand @op0, a

    if (@op0.type and @type_xn_xsp) 
        
        db 0xFF, 0xFF, 0xFF 
        db 00 + (@op0.data shl 5) + size
        
        dd address

    end if

end macro
    


The problem is that I always get "invalid address prefix". It looks that the "type" variable is not loaded from "match = type [mem_addr], type_mem"

I'm a total noob in FASM macros Sad

Any help appreciated.

Thanks!
Post 02 May 2023, 22:41
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 03 May 2023, 07:28
To compare something to a quoted string, make it into such string, too:
Code:
        if `type eq 'byte'
            size = 1
        else if `type eq 'word'
            size = 2
        else if `type eq 'dword'
            size = 3
        else if `type eq 'qword'
            size = 4
        else 
            err 'invalid address prefix'
        end if    
But I would recommend to use MATCH for everything, since EQ is more for computed values:
Code:
    match type [mem_addr], type_mem
   
        match =byte, type
            size = 1
        else match =word, type
            size = 2
        else match =dword, type
            size = 3
        else match =qword, type
            size = 4
        else 
            err 'invalid address prefix'
        end match

        address=mem_addr
   
    end match    
Also "= " in your original MATCH seems completely unnecessary, it matches the space that you have after the comma, but this whitespace would be stripped anyway (the wildcard parameters need to be matched with non-whitespace tokens).
Post 03 May 2023, 07:28
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 03 May 2023, 09:01
Excellent Tomasz! This is better support than even big companies! Very Happy

Thanks a lot!
Post 03 May 2023, 09:01
View user's profile Send private message Reply with quote
FlierMate2



Joined: 21 Mar 2023
Posts: 39
FlierMate2 03 May 2023, 13:08
alorent wrote:
This is better support than even big companies! Very Happy


I agree 100%, Tomasz as maintainer for FASM and FASMG for over 20 years! And Tomasz and revolution always stand by on forum and on Discord server, giving prompt reply with answer.
Post 03 May 2023, 13:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20214
Location: In your JS exploiting you and your system
revolution 03 May 2023, 13:13
I am not on any Discord server. If there is someone there named revolution then it isn't me.
Post 03 May 2023, 13:13
View user's profile Send private message Visit poster's website Reply with quote
FlierMate2



Joined: 21 Mar 2023
Posts: 39
FlierMate2 03 May 2023, 13:22
revolution wrote:
I am not on any Discord server. If there is someone there named revolution then it isn't me.


Oh I see! Thanks for your correction.

I thought "StaticSaga" is you.
Post 03 May 2023, 13:22
View user's profile Send private message 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.