flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro parts. How do this?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 28 Sep 2024, 08:10
Fasmw 1.73
Code:
macro mGet [a], [b] { } 
;in code 
GetBufr equ myBufferData
mGet eax, +8, ESI,+8,>2, edx
;out asm
mov eax, [GetBufr] 
Add eax, 8
mov esi, [GetBufr+4]
Add esi, 8
Shr esi, 2
mov edx, [GetBufr+8]
    
Post 28 Sep 2024, 08:10
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 28 Sep 2024, 09:23
I do this variant. But not variant from first topic.
Code:
macro mGet x,a,[p] { common
                   rept 1 n:x \{ GetBufr equ GetBufr+n \}
                   mov a,[GetBufr]
      forward
      match :,p \{ mov a,[a]
      display ':'   \}
      match =+v,p \{ add a,v
      display '+'   \}
      match =-v,p \{ sub a,v
      display '-'   \}
      match ==>v,p \{ shr a,v
      display '>'   \}
      match ==<v,p \{ shl a,v
      display '<'   \}
}
;in code
GetBufr equ edx+16
mGet 0,eax,:,=>5,+-8,+16,-4,-edx,=<2
mGet 4,esi,+8
mGet 32,edi,+16

;my question is how do this ?
mGet2 0,eax,<=>5,+-8,+16,-4,-edx,=<2> ;I want separate part params for mGet2
macro mGet2 [x,a,part] {mGet x,a,[part] }
    


Last edited by Roman on 28 Sep 2024, 09:38; edited 2 times in total
Post 28 Sep 2024, 09:23
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1040
Location: Russia
macomics 28 Sep 2024, 09:33
Code:
format PE
macro mGet [args] { common macro mGetArg base*,[arg] \{ \common mov base,[GetBufr]
        match any,GetBufr \\{ define GetBufr any+4 \\}
        \forward match =+ x, arg \\{ add base, x \\}
                 match =~ x, arg \\{ shl base, x \\}
    \}
    if ~ args eq
    forward mGetArg args
    common end if
    purge mGetArgs
}
GetBufr equ myBuffData
mGet <eax,+8>,<esi,+8, ~2>,edx
myBuffData  rd 4    

Code:
$ fasm test_mGet.asm 
flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
2 passes, 1024 bytes.

$ hexdump -C test_mGet.exe
00000000  4d 5a 80 00 01 00 00 00  04 00 10 00 ff ff 00 00  |MZ..............|
00000010  40 01 00 00 00 00 00 00  40 00 00 00 00 00 00 00  |@.......@.......|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 80 00 00 00  |................|
00000040  0e 1f ba 0e 00 b4 09 cd  21 b8 01 4c cd 21 54 68  |........!..L.!Th|
00000050  69 73 20 70 72 6f 67 72  61 6d 20 63 61 6e 6e 6f  |is program canno|
00000060  74 20 62 65 20 72 75 6e  20 69 6e 20 44 4f 53 20  |t be run in DOS |
00000070  6d 6f 64 65 2e 0d 0a 24  00 00 00 00 00 00 00 00  |mode...$........|
00000080  50 45 00 00 4c 01 01 00  d2 cd f7 66 00 00 00 00  |PE..L......f....|
00000090  00 00 00 00 e0 00 0f 01  0b 01 01 49 00 02 00 00  |...........I....|
000000a0  00 02 00 00 00 00 00 00  00 10 00 00 00 10 00 00  |................|
000000b0  00 10 00 00 00 00 40 00  00 10 00 00 00 02 00 00  |......@.........|
000000c0  01 00 00 00 00 00 00 00  03 00 0a 00 00 00 00 00  |................|
000000d0  00 20 00 00 00 02 00 00  65 60 00 00 03 00 00 00  |. ......e`......|
000000e0  00 10 00 00 00 10 00 00  00 00 01 00 00 00 00 00  |................|
000000f0  00 00 00 00 10 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000170  00 00 00 00 00 00 00 00  2e 66 6c 61 74 00 00 00  |.........flat...|
00000180  2a 00 00 00 00 10 00 00  00 02 00 00 00 02 00 00  |*...............|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 60 00 00 e0  |............`...|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  a1 1a 10 40 00 83 c0 08  8b 35 1e 10 40 00 83 c6  |...@.....5..@...|
00000210  08 c1 e6 02 8b 15 22 10  40 00 00 00 00 00 00 00  |......".@.......|
00000220  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*    

Code:
$ objdump -M intel -D test_mGet.exe

test_mGet.exe:     формат файла pei-i386


Дизассемблирование раздела .flat:

00401000 <.flat>:
  401000:       a1 1a 10 40 00          mov    eax,ds:0x40101a
  401005:       83 c0 08                add    eax,0x8
  401008:       8b 35 1e 10 40 00       mov    esi,DWORD PTR ds:0x40101e
  40100e:       83 c6 08                add    esi,0x8
  401011:       c1 e6 02                shl    esi,0x2
  401014:       8b 15 22 10 40 00       mov    edx,DWORD PTR ds:0x401022    
Post 28 Sep 2024, 09:33
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 28 Sep 2024, 09:41
Quote:

~2

If i needed do shr reg,2
What should I do?
Post 28 Sep 2024, 09:41
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1040
Location: Russia
macomics 28 Sep 2024, 09:48
Roman wrote:
If i needed do shr reg,2
What should I do?
As you can see in my code, < and > characters are used by the preprocessor when substituting arguments into macros.
e.g.
Code:
mGet <eax,+8>,<esi,+8, ~2>,edx
; mGet.arg1 = eax,+8
; mGet.arg2 = esi,+8, ~2
; mget.arg3 = edx    
=>
Code:
forward mGetArg args
; mGetArg.base = eax
; mGetArg.arg1 = +8

; mGetArg.base = esi
; mGetArg.arg1 = +8
; mGetArg.arg2 = ~2

; mGetArg.base = edx
; mGetArg.arg =    

You need to use other symbols to indicate shifts so that preprocessor does not mistake them for errors.
Post 28 Sep 2024, 09:48
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 28 Sep 2024, 09:54
Quote:

As you can see in my code, < and > characters are used by the preprocessor when substituting arguments into macros.

Did exist way to using () instead <> for preprocessor ?
Or replace ~ to :~ this shl and ~: this shr
Post 28 Sep 2024, 09:54
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1040
Location: Russia
macomics 28 Sep 2024, 10:29
Code:
format PE
macro mGet [args] { common macro mGetArg base*,[arg] \{ \common mov base,[GetBufr]
        match any,GetBufr \\{ define GetBufr any+4 \\}
        \forward match =+ x, arg \\{ add base, x \\}
                 match =:=~ x, arg \\{ shl base, x \\}
                 match =~=: x, arg \\{ shr base, x \\}
    \}
    if ~ args eq
    forward mGetArg args
    common end if
    purge mGetArgs
}
GetBufr equ myBuffData
mGet <eax,+8, ~:3>,<esi,+8, :~2>,edx
myBuffData  rd 4    


Code:
$ fasm test_mGet.asm 
flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
2 passes, 1024 bytes.
$ hexdump -C test_mGet.exe
00000000  4d 5a 80 00 01 00 00 00  04 00 10 00 ff ff 00 00  |MZ..............|
00000010  40 01 00 00 00 00 00 00  40 00 00 00 00 00 00 00  |@.......@.......|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 80 00 00 00  |................|
00000040  0e 1f ba 0e 00 b4 09 cd  21 b8 01 4c cd 21 54 68  |........!..L.!Th|
00000050  69 73 20 70 72 6f 67 72  61 6d 20 63 61 6e 6e 6f  |is program canno|
00000060  74 20 62 65 20 72 75 6e  20 69 6e 20 44 4f 53 20  |t be run in DOS |
00000070  6d 6f 64 65 2e 0d 0a 24  00 00 00 00 00 00 00 00  |mode...$........|
00000080  50 45 00 00 4c 01 01 00  56 da f7 66 00 00 00 00  |PE..L...V..f....|
00000090  00 00 00 00 e0 00 0f 01  0b 01 01 49 00 02 00 00  |...........I....|
000000a0  00 02 00 00 00 00 00 00  00 10 00 00 00 10 00 00  |................|
000000b0  00 10 00 00 00 00 40 00  00 10 00 00 00 02 00 00  |......@.........|
000000c0  01 00 00 00 00 00 00 00  03 00 0a 00 00 00 00 00  |................|
000000d0  00 20 00 00 00 02 00 00  5e b1 00 00 03 00 00 00  |. ......^.......|
000000e0  00 10 00 00 00 10 00 00  00 00 01 00 00 00 00 00  |................|
000000f0  00 00 00 00 10 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000170  00 00 00 00 00 00 00 00  2e 66 6c 61 74 00 00 00  |.........flat...|
00000180  2d 00 00 00 00 10 00 00  00 02 00 00 00 02 00 00  |-...............|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 60 00 00 e0  |............`...|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  a1 1d 10 40 00 83 c0 08  c1 e8 03 8b 35 21 10 40  |...@........5!.@|
00000210  00 83 c6 08 c1 e6 02 8b  15 25 10 40 00 00 00 00  |.........%.@....|
00000220  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*    

Code:
$ objdump -M intel -D test_mGet.exe

test_mGet.exe:     формат файла pei-i386


Дизассемблирование раздела .flat:

00401000 <.flat>:
  401000:       a1 1d 10 40 00          mov    eax,ds:0x40101d
  401005:       83 c0 08                add    eax,0x8
  401008:       c1 e8 03                shr    eax,0x3
  40100b:       8b 35 21 10 40 00       mov    esi,DWORD PTR ds:0x401021
  401011:       83 c6 08                add    esi,0x8
  401014:       c1 e6 02                shl    esi,0x2
  401017:       8b 15 25 10 40 00       mov    edx,DWORD PTR ds:0x401025
        ...    


Code:
format PE
macro mGet [args] { common macro mGetArg base*,[arg] \{ \common mov base,[GetBufr]
        match any,GetBufr \\{ define GetBufr any+4 \\}
        \forward match =+ x, arg \\{ add base, x \\}
                 match =( x, arg \\{ shl base, x \\}
                 match =) x, arg \\{ shr base, x \\}
    \}
    if ~ args eq
    forward mGetArg args
    common end if
    purge mGetArgs
}
GetBufr equ myBuffData
mGet <eax,+8, )3>,<esi,+8, (2>,edx
myBuffData  rd 4    


Code:
$ fasm test_mGet.asm 
flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
2 passes, 1024 bytes.
$ hexdump -C test_mGet.exe
00000000  4d 5a 80 00 01 00 00 00  04 00 10 00 ff ff 00 00  |MZ..............|
00000010  40 01 00 00 00 00 00 00  40 00 00 00 00 00 00 00  |@.......@.......|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 80 00 00 00  |................|
00000040  0e 1f ba 0e 00 b4 09 cd  21 b8 01 4c cd 21 54 68  |........!..L.!Th|
00000050  69 73 20 70 72 6f 67 72  61 6d 20 63 61 6e 6e 6f  |is program canno|
00000060  74 20 62 65 20 72 75 6e  20 69 6e 20 44 4f 53 20  |t be run in DOS |
00000070  6d 6f 64 65 2e 0d 0a 24  00 00 00 00 00 00 00 00  |mode...$........|
00000080  50 45 00 00 4c 01 01 00  e3 da f7 66 00 00 00 00  |PE..L......f....|
00000090  00 00 00 00 e0 00 0f 01  0b 01 01 49 00 02 00 00  |...........I....|
000000a0  00 02 00 00 00 00 00 00  00 10 00 00 00 10 00 00  |................|
000000b0  00 10 00 00 00 00 40 00  00 10 00 00 00 02 00 00  |......@.........|
000000c0  01 00 00 00 00 00 00 00  03 00 0a 00 00 00 00 00  |................|
000000d0  00 20 00 00 00 02 00 00  eb b1 00 00 03 00 00 00  |. ..............|
000000e0  00 10 00 00 00 10 00 00  00 00 01 00 00 00 00 00  |................|
000000f0  00 00 00 00 10 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000170  00 00 00 00 00 00 00 00  2e 66 6c 61 74 00 00 00  |.........flat...|
00000180  2d 00 00 00 00 10 00 00  00 02 00 00 00 02 00 00  |-...............|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 60 00 00 e0  |............`...|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  a1 1d 10 40 00 83 c0 08  c1 e8 03 8b 35 21 10 40  |...@........5!.@|
00000210  00 83 c6 08 c1 e6 02 8b  15 25 10 40 00 00 00 00  |.........%.@....|
00000220  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
    

Code:
$ objdump -M intel -D test_mGet.exe

test_mGet.exe:     формат файла pei-i386


Дизассемблирование раздела .flat:

00401000 <.flat>:
  401000:       a1 1d 10 40 00          mov    eax,ds:0x40101d
  401005:       83 c0 08                add    eax,0x8
  401008:       c1 e8 03                shr    eax,0x3
  40100b:       8b 35 21 10 40 00       mov    esi,DWORD PTR ds:0x401021
  401011:       83 c6 08                add    esi,0x8
  401014:       c1 e6 02                shl    esi,0x2
  401017:       8b 15 25 10 40 00       mov    edx,DWORD PTR ds:0x401025
        ...    
Post 28 Sep 2024, 10:29
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 28 Sep 2024, 10:41
Thanks.
Little changed your macro.
Code:
macro mGet2 [args] { common macro mGetArg af*,base*,[arg] \{ \common
        ;match any,GetBufr \\{ define GetBufr any+af
        mov base,[GetBufr+af]
        ;\\}
        \forward match =+ x, arg \\{ add base, x \\}
                 match =:=~ x, arg \\{ shl base, x \\}
                 match =~=: x, arg \\{ shr base, x \\}
                 match : , arg \\{ mov base, [base] \\}
                 match # , arg \\{ call base \\}
                 match =* x , arg \\{ x base \\}
    \}
    if ~ args eq
    forward mGetArg args
    common end if
    purge mGetArgs
}
macro mpu a {push a
call a
pop a
}
Start:   GetBufr equ edx+16
         mGet2 <0,eax,:,+8, ~:3,#>,\
               <4,esi,+8, :~2,*mpu>,\
               <16,edx,:> 
    


Last edited by Roman on 28 Sep 2024, 11:57; edited 1 time in total
Post 28 Sep 2024, 10:41
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1040
Location: Russia
macomics 28 Sep 2024, 11:36
You should not use # symbol to indicate operations, because it is also used by the preprocessor to connect operators.
Post 28 Sep 2024, 11:36
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 28 Sep 2024, 11:40
Ok.
Using &. Bad idea. Farm get error.
Idea using "&" or ">" and could using "!=" or "\" or "@"
Code:
macro mGet2 [args] { common macro mGetArg af*,base*,[arg] \{ \common
        ;match any,GetBufr \\{ define GetBufr any+af
        mov base,[GetBufr+af]
        GetReg equ base
        ;\\}
        \forward match =+ x, arg \\{ add base, x \\}
                 ;match =:=~ x, arg \\{ shl base, x \\}
                 ;match =~=: x, arg \\{ shr base, x \\}
                 match ">" x, arg \\{ shr base, x \\}
                 match "<" x, arg \\{ shl base, x \\}
                 match : , arg \\{ mov base, [base] \\}
                 match 'do' , arg \\{ call base \\}
                 match =* x , arg \\{ x base \\}
    \}
    if ~ args eq
    forward mGetArg args
    common end if
    purge mGetArgs
}  
GetBufr equ edx+16
         mGet2 <0,eax,:,+8, ">"3>,\
               <4,GetReg,+8, "<"2, 'do'>
               
    



My opinion we need set for macro special symbols using for preprocessor. Or using <\ and \> for preprocessor.
New feature for fasmw.
Post 28 Sep 2024, 11:40
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.