flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > display polynome internals: variable term used where not exp

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 23 Jul 2017, 07:53
How to extract polynome internals not into if-checks but into display?
Code:
macro displaypoly arg
  display (0 elementof arg)
  display 13,10
end macro

displaypoly eax+'b'
;shows "c"

macro displaypoly arg
  display (0 metadataof arg)
  display 13,10
end macro

displaypoly eax+'b'
;shows "b"
    

If I used 1 instead of 0 in both cases I got error: variable term used where not expected.

But how to display separate 4 values "x86.r32", "0", "x86.reg", "4", that term eax has inside of self.


Code:
macro displaypoly arg
  disphex (1 metadataof arg) - x86.r32-(0 metadataof arg),1 ;extract x86.r32 index
  display ' - index of ',`arg,' in x86.r32',13,10
  disphex 1 metadataof (1 metadataof arg) - x86.reg,1 ;extract x86.reg index
  display ' - index of ',`arg,' in x86.reg',13,10
  ;how extract x86.r32 & x86.reg theyselfs? to make macro polynome independent? now macro expects some of descendants of x86.r32
  ;in display output index of esi+'a' is wrong - should be just index of esi - how to fix that?
end macro

displaypoly esi+'a' ;ok
displaypoly esi*2+'a' ;error     

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 23 Jul 2017, 07:53
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 23 Jul 2017, 08:49
If you want to display complete tree of the metadata information, you need to use recursion:
Code:
macro displaypoly poly
        local buffer,number
        buffer = poly
        number = buffer scale 0
        if number < 0
                display '-'
                number = -number
        end if
        repeat 1, n:number
                display `n
        end repeat
        repeat elementsof buffer
                number = buffer scale %
                if number < 0
                        display '-'
                        number = -number
                else
                        display '+'
                end if
                if number <> 1
                        repeat 1, n:number
                                display `n,'*'
                        end repeat
                end if
                display '['
                displaypoly buffer metadata %
                display ']'
        end repeat
end macro

displaypoly eax+2    
This is probably still not good enough - when an element does not have a metadata it is shown simply as "[0]". As elements by themselves do not have any intrinsic meaning to the assembler, you need to somehow distinguish them yourself, this obviously would depend on what kind of elements yo expect to encounter:
Code:
macro displaypoly poly
        local buffer,number
        buffer = poly
        number = buffer scale 0
        if number < 0
                display '-'
                number = -number
        end if
        repeat 1, n:number
                display `n
        end repeat
        repeat elementsof buffer
                number = buffer scale %
                if number < 0
                        display '-'
                        number = -number
                else
                        display '+'
                end if
                if number <> 1
                        repeat 1, n:number
                                display `n,'*'
                        end repeat
                end if
                if buffer metadata %
                        display '['
                        displaypoly buffer metadata %
                        display ']'
                else if buffer element % eq x86.reg
                        display 'x86.reg'
                else
                        display 'unknown'
                end if
        end repeat
end macro

displaypoly eax+ebx*2+3    
Post 23 Jul 2017, 08:49
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 23 Jul 2017, 09:31
Thanks.
Perfect - I tested on polynomes other than general registers too.
One more question polynome element base can be send to display in anyway?
I mean value of (buffer element %) extracted itself and displayed?
Post 23 Jul 2017, 09:31
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 23 Jul 2017, 10:33
Element by itself has no value, so there is nothing to display there.
Post 23 Jul 2017, 10:33
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 23 Jul 2017, 11:09
If I override element macro itself and force defining values

Code:
macro element arg&
  element arg
  match elem:bs index,arg
    elem.name equ elem
    elem.base equ bs
  else match elem,arg
    elem.name equ elem
    elem.base equ 
  end if
end macro    


could (buffer element %).name or (buffer element %).base become available?
Post 23 Jul 2017, 11:09
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 23 Jul 2017, 12:51
The variable defined by ELEMENT is like a value of a symbol, and you cannot get back to symbol from the value.
Code:
a = 2 ; this defines "a" with known constant value 2
element b ; this defines "b" with unknown (variable) value X
c = a + b ; this defines "c" with value "1+X"
; note that "c" no longer has any information about "a" or "b", they were only used to compute the value    
Therefore when you analyze polynomial variables, you can only extract their metadata or compare two variables to see if they are the same one.

So all you could do would be to define the elements in such a way that they would contain some information for displaying purposes in their metadata. For example you could catch the definitions of elements with no metadata and insert your own metadata there:
Code:
element metaname : 'metaname' + metaname

macro element? definition
        match name:metadata, definition
                element name:metadata
        else
                element definition:`definition + metaname
        end match
end macro

; ...

macro displaypoly poly
        local buffer,number
        buffer = poly
        number = buffer scale 0
        if number < 0
                display '-'
                number = -number
        end if
        repeat 1, n:number
                display `n
        end repeat
        repeat elementsof buffer
                number = buffer scale %
                if number < 0
                        display '-'
                        number = -number
                else
                        display '+'
                end if
                if number <> 1
                        repeat 1, n:number
                                display `n,'*'
                        end repeat
                end if
                if buffer metadata % relativeto metaname
                        display string buffer metadata % scale 0
                else
                        display '['
                        displaypoly buffer metadata %
                        display ']'
                end if
        end repeat
end macro    
Because metadata can itself be a polynomial, you can even combine multiple terms for holding various kinds of information.
Post 23 Jul 2017, 12:51
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 23 Jul 2017, 14:33
Mostly for myself: the way additional info can be added so it don`t touches any behavior of standart macros that is addition as multiplier. Just affect macros described in this post.
Code:
element al? : x86.r8*'al' + 0
element cl? : x86.r8*'cl' + 1
element dl? : x86.r8*'dl' + 2
element bl? : x86.r8*'bl' + 3
element ah? : x86.r8*'ah' + 4
element ch? : x86.r8*'ch' + 5
element dh? : x86.r8*'dh' + 6
element bh? : x86.r8*'bh' + 7     
Post 23 Jul 2017, 14:33
View user's profile Send private message Send e-mail 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.