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 > debug var in macro

Author
Thread Post new topic Reply to topic
emil



Joined: 16 Dec 2003
Posts: 70
Location: egypt
debug var in macro
Hi All

consider the next macro.

Code:

macro bla 
      var = 10
      ....
      ....

end macro
    



how to print the value of var?
Post 24 Feb 2017, 15:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14805
Location: Lost in translation
Assuming you mean assembly-time printing then here is one way to do it:

https://board.flatassembler.net/topic.php?t=3979

If that doesn't work for you then there are other solutions posted also.
Post 24 Feb 2017, 16:02
View user's profile Send private message Visit poster's website Reply with quote
emil



Joined: 16 Dec 2003
Posts: 70
Location: egypt
Oh , sorry , i was asking for famg not fasm1.
Post 24 Feb 2017, 16:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14805
Location: Lost in translation
There are existing solutions posted for fasmg also. Maybe one of them will work for you.
Post 24 Feb 2017, 16:22
View user's profile Send private message Visit poster's website Reply with quote
emil



Joined: 16 Dec 2003
Posts: 70
Location: egypt
may you point me to one of them please.
Post 24 Feb 2017, 16:28
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6357
Location: Kraków, Poland
If you just need to quickly peek at a number and decimal representation is enough for you, you can use this simple trick (inherited from fasm's REPT):

Code:
var = 10

rept 1xvar
    display `x
end rept

If you'd prefer to show number as hexadecimal, you may use a macro similar to the ones that exist for fasm:

Code:
macro disphex? value*
        local number,digit   
        number = value   
        if number < 0   
                display '-'
                number = - number   
        end if   
        repeat 1 + (bsr number shr 2)   
                digit = ((numbershr ((%%-%shl 2)) and 0Fh
                if % = 1 & digit > 9
                        display '0'
                end if
                if digit < 10
                        display '0'+digit
                else
                        display 'A'+digit-10
                end if
        end repeat   
        display 'h'
end macro

disphex var

Then there is another macro that you can use to display floating-point numbers.

And then you could even combine various macros into one able to display various types of values:

Code:
macro disphex? value*
        local number,digit   
        number = value   
        if number < 0   
                display '-'
                number = - number   
        end if   
        repeat 1 + (bsr number shr 2)   
                digit = ((numbershr ((%%-%shl 2)) and 0Fh
                if % = 1 & digit > 9
                        display '0'
                end if
                if digit < 10
                        display '0'+digit
                else
                        display 'A'+digit-10
                end if
        end repeat   
        display 'h'
end macro

macro dispfloat? value*,precision:2
        local x,i,pos,sgn,dgt,txt 
        x = value 
        x = x * 1e#precision 
        sgn = 0 
        if x < 0 
                x = -x 
                sgn = 1  
        end if  
        i = trunc x 
        if x - i >= float 1/2 
                i = i + 1 
        end if 
        pos = 0 
        txt = '' 
        while i | pos <= precision 
                dgt = i mod 10 
                i = i / 10 
                txt = txt shl 8 + '0' + dgt 
                pos = pos + 1 
                if pos = precision 
                        txt = txt shl 8 + '.' 
                end if 
        end while  
        if sgn  
                txt = txt shl 8 + '-'  
        end if
        display string txt
end macro

macro dispx? values&
        iterate valuevalues
                if value eqtype ''
                        display value
                else if value eqtype 1f
                        dispfloat value
                else if value eqtype 0 & value relativeto 0
                        disphex value
                else
                        err 'unsupported kind of value'
                end if
        end iterate
        display 13,10
end macro

; Usage example:

x = 10
y = 3.14

dispx 'x = ',x,' & y = ',y

It could be further extended to show linear polynomial values, but that would depend on what kind of ELEMENT symbols you have defined.
Post 24 Feb 2017, 16:53
View user's profile Send private message Visit poster's website Reply with quote
emil



Joined: 16 Dec 2003
Posts: 70
Location: egypt
thanks Tomasz.

is the first one work from inside any macro?
Post 24 Feb 2017, 17:04
View user's profile Send private message Reply with quote
emil



Joined: 16 Dec 2003
Posts: 70
Location: egypt
ok , i have test it , and feet my need.
Post 24 Feb 2017, 17:44
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


Powered by phpBB © 2001-2005 phpBB Group.

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