flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Include from files blocks for macro

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 13 Mar 2024, 06:36
In fasmw 1.73 i don't like writing macros for all situations and any steps.
Macros getting too much.

My idea include from files blocks for macro.
Example:
Code:
nameFile equ MovX86.txt
;in file MovX86.txt
[mov] mov p1,p2
          mov [p2],11
..  ;mean end this block. One block could have many asm commands. Thousands. 
[add] add p1,p2
..
;end file MovX86.txt

macro commands c,p1,p2 {
if c eq mov
 file nameFile from '[mov]'
end if
}

macro any c,p1,p2 {
 file nameFile from '['+`c+']'
}
;in code
any mov,eax,ebx
any add,eax,11
    


Now we easy changed arm to x86 commands file.
Or changed macro on fly.
Code:
 
;in file MovX86.txt
[mov] mov p1,p2
          mov [p2],11
..  ;mean end this block

;in file MovX86b.txt
[mov] mov [p1],p2
          add [p2],10
..  ;mean end this block

macro commands c,p1,p2 {
if c eq mov
 file nameFile from '[mov]'
end if
}
;in code
nameFile equ MovX86.txt
commands mov,eax,ebx

nameFile equ MovX86b.txt
commands mov,eax,ebx

    
Post 13 Mar 2024, 06:36
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 13 Mar 2024, 07:29
Or this variant
Code:
nameFile equ "MovX86.txt"
;in file MovX86.txt
mov \{ mov p1,p2
          mov [p2],11
\}  ;mean end this block. One block could have many asm commands. Thousands. 
add \{ add p1,p2
\}
;end file MovX86.txt



macro any c,p1,p2 {
include nameFile from c
}
;in code
any mov,eax,ebx
any add,eax,11
    
Post 13 Mar 2024, 07:29
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 913
Location: Russia
macomics 13 Mar 2024, 08:10
MovX86.txt
Code:
match =[=mov=], nameCmd {
    macro _mov p1, p2 \{
        mov p1,p2
        mov byte [p2],11
    \}
}

match =[=add=], nameCmd {
    macro _add p1, p2 \{
        add p1,p2
    \}
}    

main.asm
Code:
nameFile    equ 'MovX86.txt'
macro commands c,p1,p2 {
    if c eq mov
        nameCmd equ [mov]
        match name, nameFile \{ include name \}
        _mov p1,p2
        purge _mov
        restore nameCmd
    end if
}

macro any c,p1,p2 {
    nameCmd equ [#c#]
    match name, nameFile \{ include name \}
    _#c p1,p2
    purge _#c
    restore nameCmd
}

;in code
any mov,eax,ebx
any add,eax,11    


Code:
$ fasm main.asm
flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
1 passes, 11 bytes.

$ hexdump -C main.bin
00000000  66 89 d8 67 c6 03 0b 66  83 c0 0b                 |f..g...f...|
0000000b    


Code:
use16
66 89 d8:    mov eax,ebx
67 c6 03 0b: mov byte [ebx],11
66 83 c0 0b: add eax,11    
Post 13 Mar 2024, 08:10
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 13 Mar 2024, 10:01
macomics Thanks.
Awesome !
Post 13 Mar 2024, 10:01
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.