flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Help creating this macro, please.

Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 201
alorent
Hello,

I'm a bit stuck trying to convert the following MASM macro into FASM. I have searched but cannot find a similar macro (where the macro is asigned to an instruction). This is the MASM macro:

Code:
MAKE_VALUE macro rg, rb

   local    Value

   Value = (rg shl 4) or rb 
   exitm %Value  

endm


BASE8              EQU     1
BASE16             EQU     2

VAL_1           EQU     MAKE_VALUE(BASE8, 1)
VAL_2           EQU     MAKE_VALUE(BASE8, 2)


; testing the waters....

mov    eax, VAL_1   ; EAX = (1 << 4) or 1
mov         eax, VAL_2   ; EAX = (1 << 4) or 2    


Any help, please?

Thanks!
Post 27 May 2010, 10:32
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
alorent,

Macro functions are not (yet?) allowed in FASM. Probably struc macro will help?
Code:
struc MAKE_VALUE rg, rb { . equ ((rg) shl 4 or (rb)) }

BASE8   equ     1
BASE16  equ     2
VAL_1   MAKE_VALUE BASE8, 1
VAL_2   MAKE_VALUE BASE8, 2

mov     eax, VAL_1   ; EAX = (1 << 4) or 1
mov     eax, VAL_2   ; EAX = (1 << 4) or 2    
Post 27 May 2010, 10:49
View user's profile Send private message Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 201
alorent
Thanks baldr!!! That did the trick! Wink

Thanks!
Post 27 May 2010, 11:44
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
There is another trick to simulate macro functions:
Code:
struc reequ [val] {
common
  restore .
  . equ val
}

macro ^ [args] {
common
  local head, expr, tail, matched
  head equ
  expr equ
  tail equ
  matched equ 0
  match _head =~ _expr =~ _tail, args \{
    head reequ _head
    expr reequ _expr
    tail reequ _tail
    matched reequ 1
  \}
  match =0 _head =~ _expr =~, matched args \{
    head reequ _head
    expr reequ _expr
    matched reequ 1
  \}
  match =0 =~ _expr =~ _tail, matched args \{
    expr reequ _expr
    tail reequ _tail
    matched reequ 1
  \}
  match =1, matched \{
    \local val
    match _expr, expr \\{
      val _expr
      head val tail
    \\}
    restore val
  \}
  match =0, matched \{ args \}
  restore head, expr, tail, matched
}

struc RGB r, g, b { . equ (((r) shl 8 or (g)) shl 8 or (b)) }

^       mov     eax, ~RGB 1,2,3~+0xFF000000
^ magenta = ~RGB 255, 0, 255~
        mov     ecx, magenta    
«^» is a prefix macro, it searches arguments for something enclosed in «~»s. This fragment is supposed to be «struc_name args»; macro invokes it as «val struc_name args» and replaces that fragment with val. The result of replacement is then used as instruction.
Post 27 May 2010, 12:15
View user's profile Send private message Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 201
alorent
Thanks baldr! Amazing your understanding in FASM macros!!! Very Happy
Post 27 May 2010, 12:26
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.