flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
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 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 |
|||
![]() |
|
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? |
|||
![]() |
|
Tomasz Grysztar 23 Jul 2017, 10:33
Element by itself has no value, so there is nothing to display there.
|
|||
![]() |
|
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? |
|||
![]() |
|
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 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 |
|||
![]() |
|
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 |
|||
![]() |
|
m_stery 14 Mar 2025, 10:04
Another solution would be to store the symbols under a numerical name and the polynomial with the corresponding coefficients.
Example written using calm language (elements+area labels): Code: calminstruction calminstruction?.initsym? var*,val& publish var,val end calminstruction define polynomial_debug? polynomial_debug? namespace polynomial_debug? define elemnames elemnames polyids = 0 calminstruction element? decl& local sym,name,mdata,i arrange name,decl arrange decl,=element decl assemble decl match name:mdata,name compute polyids,polyids+1+(1+0 scaleof polyids)*name compute i,0 scaleof polyids arrange sym,elemnames.i? publish sym:,name end calminstruction calminstruction (name) arealabel? decl& local sym,mdata,any,i match ::any?,decl arrange decl,name decl assemble decl jyes area_label exit area_label: compute polyids,polyids+1+(1+0 scaleof polyids)*name compute i,0 scaleof polyids arrange sym,elemnames.i? publish sym:,name end calminstruction ;returns a polynomial with the same elements but coefficients corresponding to the numerical name calminstruction polynomial_ids? dest*,src* local value,ivalue,rvalue,noe,i,eid compute value,src compute noe,elementsof value compute ivalue,0 compute i,1 elem: check i<=noe jno ready compute ivalue,ivalue+i elementof value compute i,i+1 jump elem ready: compute ivalue,ivalue+polyids compute i,1 compute rvalue,0 getid: check i<=noe jno done compute eid,(i scaleof ivalue)-1 check eid=0 jyes unknownid compute rvalue,rvalue+eid*i elementof ivalue compute i,i+1 jump getid unknownid: compute rvalue,rvalue-i elementof ivalue compute i,i+1 jump getid done: publish dest,rvalue end calminstruction calminstruction polynomial_text_ids? dest*,src* local value,ivalue,rvalue,noe,i,sym,eid,coef initsym sym,ivalue call polynomial_ids,sym,src compute value,src compute noe,elementsof value compute coef,0 scaleof value check coef<0 jyes minus_sign0 arrange rvalue,+coef jump ready minus_sign0: compute coef,-coef arrange rvalue,-coef ready: compute i,1 loop: check i<=noe jno done compute eid,i scaleof ivalue compute coef,i scaleof value compute i,i+1 check coef<0 jyes minus_sign arrange rvalue,rvalue+coef jump elname minus_sign: compute coef,-coef arrange rvalue,rvalue-coef elname: check eid>0 jyes valid_id arrange rvalue,rvalue*? jump loop valid_id: arrange rvalue,rvalue*?eid? jump loop done: transform rvalue,elemnames publish dest,rvalue end calminstruction end namespace mvmacro element?,polynomial_debug?.element? mvstruc ?,polynomial_debug?.arealabel? and example: Code: calminstruction symdisplay? var* local tmp arrange tmp,var transform tmp arrange tmp,var==tmp stringify tmp display tmp bappend 10 end calminstruction include 'packages/fasm2/fasm2.inc' direct:: db 'cba' define sr someterm = ax - bx + 3*cs - 100*eax + direct polynomial_debug.polynomial_text_ids sr,someterm symdisplay sr ;display: sr=+0+1*ax?-1*bx?+3*cs?-100*eax?+1*direct |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.