flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > fasm1 tricks

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 799
Location: Russian Federation, Sochi
ProMiNick 30 Nov 2023, 23:46
Code:
; macro for switching state of symbolic variable between undefined and empty 
macro defineback arg {
        match =arg,arg \{ define defineback define \}
        match ,arg \{ define defineback restore \}
        match define,defineback \{ define arg  \} }

; assembler of course acept signed integer values, but float values loaded as unsigned integer representation of double float
; so macro to force numerical variable to be signed
macro force_signed X,bits:64 { X=(-1) shl (bits-1) + 1 shl (bits-1) xor (X) }
macro force_unsigned X,bits:64 { X=(-1) shl (bits) xor (X) }

; macro that return qword from double
; used
; (X) shr 64 shl 64 - return +0/-0 from X
; (X) shr 64 or 1 - return +1/-1 from X - multiplier to get absolute of X
macro integer X { local exp
        force_signed X
        exp=((X) shr 52 and $7FF)-$3FF-52
        if exp<-52
                X=(X) shr 64 shl 64 
        else
                ;if exp > 12
                ;        not fit in qword
                ;else
                        X=(((X) and (1 shl 52 - 1)+1 shl 52) shl exp) * ((X) shr 64 or 1)
                ;end if
        end if     

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 30 Nov 2023, 23:46
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 02 Dec 2023, 12:20
I try this.

Code:
macro defineback arg { arg#._ equ 0
        match =arg,arg \{ define defineback define \}
        match ,arg \{ define defineback restore
                      display "rest",13,10
                      arg#._ equ 1
        \}
;very interesting match again do macro defineback ! Recursion
        match define,defineback \{
         if arg#._ eq 0
        define arg
                      display "init",13,10
                      ;guQuess_ equ 2
                      end if
        \}
        display arg#._+48,13,10
        } 
;in code
rept 6  {   defineback seggg
       mov eax,seggg._
       if seggg._ eq 0
          mov ebx,11
       end if
       } 
    


Sometimes I need two macros.
First macro as parent for second.
Code:
macrA     ;in macrA hiding defineback
Some code
macrB  ;if comment macrA , macrB ignored    
    
Post 02 Dec 2023, 12:20
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.