flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > Match symbols for .if.QWORD macro

Author
Thread Post new topic Reply to topic
alwaysnub



Joined: 30 Mar 2013
Posts: 26
Match symbols for .if.QWORD macro
Iv been working on macro's to help with QWORD operations. I'm having trouble getting my .if.QWORD macro to work as desired though.

The syntax is as follows:

Reg:Reg [Mem]
[Mem] Reg:Reg
[Mem] Imm32:Imm32

> 'greater than'
< 'less than'
>= 'greater or equal to'
<= 'less or equal to'
<> 'not equal'
= 'equal'

This example produces the error: Invalid Operand "CMP DWORD[ESI+4],=0"


Code:
.if.QWORD [ESI] >= 0:0x200000
.endif 



Here is the macro code:


Code:
macro .if.QWORD [arg]
{
    __IF equ
    local ..endif
    __ENDIF equ ..endif
    local ..else
    __ELSE equ ..else
    JMP!COND.QWORD __ELSE,arg
}

macro .endif
{
    if __IF eq
        __ELSE:
    end if
    __ENDIF:
    restore __ELSE
    restore __ENDIF
    restore __IF
}

macro JMP!COND.QWORD label,arg
{
    DONE equ NO
    local ...ifcode
    __IFCODE equ ...ifcode
    match HiDword:LoDword Op [MemQword], arg
    \{
         match >, Op
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JB label
               JA __IFCODE
               CMP LoDword,DWORD [MemQword]
               JBE label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<, Op
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JA label
               JB __IFCODE
               CMP LoDword,DWORD [MemQword]
               JAE label
               __IFCODE:
               DONE reequ YES
         \\}
         match >==, Op
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JB label
               JA __IFCODE
               CMP LoDword,DWORD [MemQword]
               JB label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<==, Op
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JA label
               JB __IFCODE
               CMP LoDword,DWORD [MemQword]
               JA label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<>, Op
         \\{
               CMP LoDword,DWORD [MemQword]
               JNE __IFCODE
               CMP HiDword,DWORD [MemQword+4]
               JE label
               __IFCODE:
               DONE reequ YES
         \\}
         match ==, Op
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JNE label
               CMP LoDword,DWORD [MemQword]
               JNE label
               __IFCODE:
               DONE reequ YES
         \\}
    \}
    match [MemQwordOp HiDword:LoDwordarg
    \{
         match >, Op
         \\{
               CMP DWORD [MemQword+4],HiDword
               JB label
               JA __IFCODE
               CMP DWORD [MemQword],LoDword
               JBE label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<, Op
         \\{
               CMP DWORD [MemQword+4],HiDword
               JA label
               JB __IFCODE
               CMP DWORD [MemQword],LoDword
               JAE label
               __IFCODE:
               DONE reequ YES
         \\}
         match >==, Op
         \\{
               CMP DWORD [MemQword+4],HiDword
               JB label
               JA __IFCODE
               CMP DWORD [MemQword],LoDword
               JB label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<==, Op
         \\{
               CMP DWORD [MemQword+4],HiDword
               JA label
               JB __IFCODE
               CMP DWORD [MemQword],LoDword
               JA label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<>, Op
         \\{
               CMP DWORD [MemQword],LoDword
               JNE __IFCODE
               CMP DWORD [MemQword+4],HiDword
               JE label
               __IFCODE:
               DONE reequ YES
         \\}
         match ==, Op
         \\{
               CMP DWORD [MemQword+4],HiDword
               JNE label
               CMP DWORD [MemQword],LoDword
               JNE label
               __IFCODE:
               DONE reequ YES
         \\}
    \}
    match =NODONE \{ err \}
    restore __IFCODE
    restore DONE


Post 15 Mar 2017, 13:57
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14585
Location: Planet Dirt
For each symbol you need to place the equals before it.


Code:
match =<, op ;match to "<"
match ===<, op ;match to "=<"

Post 15 Mar 2017, 14:05
View user's profile Send private message Visit poster's website Reply with quote
alwaysnub



Joined: 30 Mar 2013
Posts: 26
@revolution

I did as you suggested, however. I still end up with the same error. It appears that the equal symbol is getting split from the other symbol when the syntax is being matched:


Code:
match [MemQwordOp HiDword:LoDwordarg



[ESI] >= 0:0x200000

gets matched as:

MemQword = "ESI"
Op = ">"
HiDword = "=0"
LoDword = "0x200000"
Post 15 Mar 2017, 14:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14585
Location: Planet Dirt
You need to change the order you do the matches. Match on the longest ops first then the shorter ops after.
Post 15 Mar 2017, 14:32
View user's profile Send private message Visit poster's website Reply with quote
alwaysnub



Joined: 30 Mar 2013
Posts: 26

revolution wrote:
You need to change the order you do the matches. Match on the longest ops first then the shorter ops after.



I did as suggested, still same error.

Current macro code


Code:
macro JMP!COND.QWORD label,arg
{
    DONE equ NO
    local ...ifcode
    __IFCODE equ ...ifcode
    match HiDword:LoDword Op [MemQword], arg
    \{
         match =>==, Op
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JB label
               JA __IFCODE
               CMP LoDword,DWORD [MemQword]
               JBE label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<==, Op
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JA label
               JB __IFCODE
               CMP LoDword,DWORD [MemQword]
               JAE label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<=>, Op
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JB label
               JA __IFCODE
               CMP LoDword,DWORD [MemQword]
               JB label
               __IFCODE:
               DONE reequ YES
         \\}
         match =>, Op
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JA label
               JB __IFCODE
               CMP LoDword,DWORD [MemQword]
               JA label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<, Op
         \\{
               CMP LoDword,DWORD [MemQword]
               JNE __IFCODE
               CMP HiDword,DWORD [MemQword+4]
               JE label
               __IFCODE:
               DONE reequ YES
         \\}
         match ==, Op
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JNE label
               CMP LoDword,DWORD [MemQword]
               JNE label
               __IFCODE:
               DONE reequ YES
         \\}
    \}
    match [MemQwordOp HiDword:LoDwordarg
    \{
         match =>==, Op
         \\{
               CMP DWORD [MemQword+4],HiDword
               JB label
               JA __IFCODE
               CMP DWORD [MemQword],LoDword
               JBE label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<==, Op
         \\{
               CMP DWORD [MemQword+4],HiDword
               JA label
               JB __IFCODE
               CMP DWORD [MemQword],LoDword
               JAE label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<=>, Op
         \\{
               CMP DWORD [MemQword+4],HiDword
               JB label
               JA __IFCODE
               CMP DWORD [MemQword],LoDword
               JB label
               __IFCODE:
               DONE reequ YES
         \\}
         match =>, Op
         \\{
               CMP DWORD [MemQword+4],HiDword
               JA label
               JB __IFCODE
               CMP DWORD [MemQword],LoDword
               JA label
               __IFCODE:
               DONE reequ YES
         \\}
         match =<, Op
         \\{
               CMP DWORD [MemQword],LoDword
               JNE __IFCODE
               CMP DWORD [MemQword+4],HiDword
               JE label
               __IFCODE:
               DONE reequ YES
         \\}
         match ==, Op
         \\{
               CMP DWORD [MemQword+4],HiDword
               JNE label
               CMP DWORD [MemQword],LoDword
               JNE label
               __IFCODE:
               DONE reequ YES
         \\}
    \}
    match =NODONE \{ err \}
    restore __IFCODE
    restore DONE


Post 15 Mar 2017, 16:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14585
Location: Planet Dirt
Now expand each match explicitly without the sub-matches:

Code:
match [MemQword] =>== HiDword=:LoDwordarg

Post 15 Mar 2017, 16:48
View user's profile Send private message Visit poster's website Reply with quote
alwaysnub



Joined: 30 Mar 2013
Posts: 26

revolution wrote:
Now expand each match explicitly without the sub-matches:

Code:
match [MemQword] =>== HiDword=:LoDwordarg




Ok, i did that and was still getting the error but this time it was because it was also matching ">=" to ">" ... So i added another match to see if a match has already been done.

Here is the macro code: (Should work now...) Thanks revolution!


Code:
macro JMP!COND.QWORD label,arg
{
    DONE equ NO
    local ...ifcode
    __IFCODE equ ...ifcode
    match HiDword=:LoDword =>== [MemQword], arg
    \{
          CMP HiDword,DWORD [MemQword+4]
          JB label
          JA __IFCODE
          CMP LoDword,DWORD [MemQword]
          JBE label
          __IFCODE:
          DONE reequ YES
    \}
    match HiDword=:LoDword =<== [MemQword], arg
    \{
          CMP HiDword,DWORD [MemQword+4]
          JA label
          JB __IFCODE
          CMP LoDword,DWORD [MemQword]
          JAE label
          __IFCODE:
          DONE reequ YES
    \}
    match HiDword=:LoDword =<=> [MemQword], arg
    \{
          CMP HiDword,DWORD [MemQword+4]
          JB label
          JA __IFCODE
          CMP LoDword,DWORD [MemQword]
          JB label
          __IFCODE:
          DONE reequ YES
    \}
    match =NODONE
    \{
         match HiDword=:LoDword => [MemQword], arg
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JA label
               JB __IFCODE
               CMP LoDword,DWORD [MemQword]
               JA label
               __IFCODE:
               DONE reequ YES
         \\}
         match HiDword=:LoDword =< [MemQword], arg
         \\{
               CMP LoDword,DWORD [MemQword]
               JNE __IFCODE
               CMP HiDword,DWORD [MemQword+4]
               JE label
               __IFCODE:
               DONE reequ YES
         \\}
         match HiDword=:LoDword == [MemQword], arg
         \\{
               CMP HiDword,DWORD [MemQword+4]
               JNE label
               CMP LoDword,DWORD [MemQword]
               JNE label
               __IFCODE:
               DONE reequ YES
         \\}
    \}
    match [MemQword] =>== HiDword=:LoDwordarg
    \{
          CMP DWORD [MemQword+4],HiDword
          JB label
          JA __IFCODE
          CMP DWORD [MemQword],LoDword
          JBE label
          __IFCODE:
          DONE reequ YES
    \}
    match [MemQword] =<== HiDword=:LoDwordarg
    \{
          CMP DWORD [MemQword+4],HiDword
          JA label
          JB __IFCODE
          CMP DWORD [MemQword],LoDword
          JAE label
          __IFCODE:
          DONE reequ YES
    \}
    match [MemQword] =<=> HiDword=:LoDwordarg
    \{
          CMP DWORD [MemQword+4],HiDword
          JB label
          JA __IFCODE
          CMP DWORD [MemQword],LoDword
          JB label
          __IFCODE:
          DONE reequ YES
    \}
    match =NODONE
    \{
         match [MemQword] => HiDword=:LoDwordarg
         \\{
               CMP DWORD [MemQword+4],HiDword
               JA label
               JB __IFCODE
               CMP DWORD [MemQword],LoDword
               JA label
               __IFCODE:
               DONE reequ YES
         \\}
         match [MemQword] =< HiDword=:LoDwordarg
         \\{
               CMP DWORD [MemQword],LoDword
               JNE __IFCODE
               CMP DWORD [MemQword+4],HiDword
               JE label
               __IFCODE:
               DONE reequ YES
         \\}
         match [MemQword] == HiDword=:LoDwordarg
         \\{
               CMP DWORD [MemQword+4],HiDword
               JNE label
               CMP DWORD [MemQword],LoDword
               JNE label
               __IFCODE:
               DONE reequ YES
         \\}
    \}
    match =NODONE \{ err \}
    restore __IFCODE
    restore DONE


Post 15 Mar 2017, 17:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14585
Location: Planet Dirt
You might want to consider incorporating the DONE match into each stage.

Code:
match =NO HiDword=:LoDword =<=> [MemQword], DONE arg

Post 15 Mar 2017, 18:02
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.