flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > macro display [any] { display any }

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 25 May 2014, 17:15
Code:
macro display [any] { display any }    

This macro extend the syntax of assembler directive allowing parameters to be stored at preprocessor time.

example:
Code:
numeric = 0
symbol equ eryyr,eyt,3

;w/o using this macro
display `numeric ; - cause error and stop compilation
display `symbol ; - same case
    


Last edited by ProMiNick on 25 May 2014, 19:31; edited 2 times in total
Post 25 May 2014, 17:15
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 25 May 2014, 18:57
in addition of display family macros:
Code:
macro display_Hex bits,value
{   if value<0
      display "not implemented neg value conversion to HEX",13,10
    else
      display '0x'
      repeat bits/4
        d = '0' + value shr (bits-%*4) and 0Fh
        if d > '9'
            d = d + 'A'-'9'-1
        end if
        display d
      end repeat
    end if }
    

Code:
macro display_Int value
{   temp = value
    if temp <0
      display '-'
      temp = -temp
    end if
    virtual at 0
      if temp=0
        db '0'
      end if
      while temp>0
        d = '0' + temp mod 10
        db d
        temp = temp / 10
      end while
      repeat $
        load d byte from $-%
        display d
      end repeat
    end virtual }
    


use example:
Code:
  numeric = 0FFFFFFFFFFFFFFFFh
  display_Hex 64,numeric ; displays a value 0xFFFFFFFFFFFFFFFF
  display_Int numeric ; displays a value 18446744073709551615
    

disadvantage:
display_Hex not operate on neg values. Who may resolve this?
And is any idea how to make this 2 macros more ellegant? your alternative?
Post 25 May 2014, 18:57
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 25 May 2014, 19:30
another one macro
Code:
macro analize_symbol symbol
{
  match , symbol\{ display \`symbol\#" is empty",13,10 \}
  match =symbol, symbol\{ display "undefined:" \}
  match pattern, symbol
  \{
    q=0
    irp value,pattern \\{ q = q+1 \\}
    display \`symbol\#"`s value of "
    display_Int q ;see the previous reply about macro display_Int   
    display " items: {"
    irps value,pattern \\{ display \\`value \\}
    display "}",13,10
  \}

}
    


use example:
Code:
  analize_symbol ssymbol ; at that point ssymbol is undefined and it`s value ssymbol own
  ssymbol equ
  analize_symbol ssymbol ; here ssymbol has an empty value
  ssymbol equ anything
  analize_symbol ssymbol ; here ssymbol has a single value anything
  ssymbol equ ssymbol,<something,and_something else,etc> 
  analize_symbol ssymbol ; here ssymbol has two values anything and value between brackets <>
  restore ssymbol 
  analize_symbol ssymbol  ; again single value
    
Post 25 May 2014, 19:30
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 25 May 2014, 20:14
macro for testing brackets <>, and for count max nesting level
Code:
macro analize_nesting symbol
{
  q = 0
  d = 0
  e = 0 ;error flag
  match , symbol \{ display \`symbol\#"`s " \}
  match pattern, symbol
  \{
    display \`symbol\#"`s "
    irps value,pattern
    \\{
      if d <0 ; found closed bracked before open bracked
        e = 1
      end if
      if value eq <
        d = d +1
      end if
      if value eq >
        d = d -1
      end if
      if d > q
        q = d
      end if
    \\}
  \}
  if d
    e = 1
  end if
  if e
    display "brackets <> unresolved"
  else
    display " max nesting level is "
    display_Int q
  end if 
  display 13,10
}
    


use example:
Code:
ssymbol equ gh<fd,gh>,<<tgrt,>,>,
analize_nesting ssymbol ; 2 level
ssymbol equ gh<fd,gh>,<<tgrt,>,>>><<,
analize_nesting ssymbol ; unresolved nesting
    


use all above macros to debug preprocess state
Post 25 May 2014, 20:14
View user's profile Send private message Send e-mail Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc 25 May 2014, 22:35
ProMiNick
Quote:
in addition of display family macros

Try to output the value (-1) shl 64 Wink .

Quote:
display_Hex not operate on neg values. Who may resolve this?
And is any idea how to make this 2 macros more ellegant? your alternative?

Here is an extension of the display directive, working with positive and negative binary, decimal and hexadecimal values (including the tricky value above). Even though this version overloads the display directive, I later decided to refrain from that and renamed the macro into xdisplay. Otherwise the preprocessor output is cluttered with unnecessary expansions each time the display directive is invoked in a conservative way.

_________________
Faith is a superposition of knowledge and fallacy
Post 25 May 2014, 22:35
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 26 May 2014, 17:01
Thanks I_inc. Your macros are that i was looking for.
Post 26 May 2014, 17:01
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 27 May 2014, 23:08
There`s set of macro for minor debuging of some statements.

macro pattern - displays pattern of any symbols exept {}/;
(This is reworked version of my earlier coded macro analize_symbol)
Code:
macro pattern token*
{
  match pattern, token
  \{
    irps value,pattern \\{
        if \\`value eq \\value
          display '"',\\`value,'"' ; some operands of calculations could be a single char strings, and they should displayed correctly
        else
          display \\`value\\#" "
        end if
 \\}
  \}
}
    


Than, macro dispDec (Thanks to l_inc).
Its internals renamed (I add suffix DBG to all) for case to explore original ones.
I apologize to author for my plagiarism. But i don`t know how to make links on this site and my english is bad enough(((
Code:
macro dispDecDBG numDBG*, paddingDBG, leaderDBG, trailerDBG
{ 
    local digCountDBG,tenPowDBG,numberDBG,lastdigDBG
        numberDBG = numDBG
        lastdigDBG = numberDBG
     
    if numberDBG < 0
            display '-' 
               numberDBG = (-(numberDBG shr 1 + numberDBG and 1)) / 5
               lastdigDBG = -(lastdigDBG + numberDBG*5 + numberDBG*5)
  else 
                numberDBG = numberDBG/10
          lastdigDBG = lastdigDBG mod 10
    end if 
      digCountDBG = 0
        tenPowDBG = 1
  while tenPowDBG <= numberDBG
           tenPowDBG = tenPowDBG*10
          digCountDBG = digCountDBG + 1
     end while 
   if ~ leaderDBG eq
              display leaderDBG
      end if 
      if ~ paddingDBG eq
             if digCountDBG < paddingDBG
                    times (paddingDBG-digCountDBG-1) display '0'
            end if 
      end if 
      repeat digCountDBG
             tenPowDBG = tenPowDBG/10
          display numberDBG/tenPowDBG+'0'
         numberDBG = numberDBG mod tenPowDBG
  end repeat 
  display lastdigDBG+'0'
       if ~ trailerDBG eq
             display trailerDBG
     end if
}
    


And finally the main macro - macro debug

btw. it can be realized on dispBin or dispHex not only on dispDec.

Code:
macro debug sttmnt*
{ display 13,10,"dbg:"
   if % >0 ; numeric % - defined everywhere in code, but outside the circles its equal to 0
    display "iteration "
    dispDecDBG %
    display ":"
  end if
  pattern sttmnt
  display "="
  match nmrc == eqtn, sttmnt \{
  dispDecDBG eqtn
  sttmnt ; do the statement, if that`s realy statement and it has an assignment
  dbgdonE equ
  \}
  match =dbgdonE, dbgdonE \{
  dispDecDBG sttmnt ; only display
  restore dbgdonE
  \}
  display 13,10
}
    


as the use example
the macro i most liked):
Code:
macro dispDec num*, padding, leader, trailer
{ 
    local digCount,tenPow,number,lastdig
        number = num
        lastdig = number
     
    if number < 0
            display '-' 
               debug number = (-(number shr 1 + number and 1)) / 5
               debug lastdig = -(lastdig + number*5 + number*5)
  else 
                debug number = number/10
          debug lastdig = lastdig mod 10
    end if 
      digCount = 0
        tenPow = 1
  while tenPow <= number
           debug tenPow = tenPow*10
          debug digCount = digCount + 1
     end while 
   if ~ leader eq
              display leader
      end if 
      if ~ padding eq
             if digCount < padding
                    debug padding-digCount-1 ; only display
                    times (padding-digCount-1) display '0'
            end if 
      end if 
      repeat digCount
             debug tenPow = tenPow/10
          display number/tenPow+'0'
         debug number = number mod tenPow
  end repeat 
  display lastdig+'0'
       if ~ trailer eq
             display trailer
     end if
}
    
Code:
dispDec  436326
    

To window Compile displayed the next: (as you can see between the dbg lines there`s normal display output)

Quote:

dbg:number?2 = number?2 / 10 =43632

dbg:lastdig?3 = lastdig?3 mod 10 =6

dbg:iteration 1:tenPow?1 = tenPow?1 * 10 =10

dbg:iteration 1:digCount?0 = digCount?0 + 1 =1

dbg:iteration 2:tenPow?1 = tenPow?1 * 10 =100

dbg:iteration 2:digCount?0 = digCount?0 + 1 =2

dbg:iteration 3:tenPow?1 = tenPow?1 * 10 =1000

dbg:iteration 3:digCount?0 = digCount?0 + 1 =3

dbg:iteration 4:tenPow?1 = tenPow?1 * 10 =10000

dbg:iteration 4:digCount?0 = digCount?0 + 1 =4

dbg:iteration 5:tenPow?1 = tenPow?1 * 10 =100000

dbg:iteration 5:digCount?0 = digCount?0 + 1 =5

dbg:iteration 1:tenPow?1 = tenPow?1 / 10 =10000
4
dbg:iteration 1:number?2 = number?2 mod tenPow?1 =3632

dbg:iteration 2:tenPow?1 = tenPow?1 / 10 =1000
3
dbg:iteration 2:number?2 = number?2 mod tenPow?1 =632

dbg:iteration 3:tenPow?1 = tenPow?1 / 10 =100
6
dbg:iteration 3:number?2 = number?2 mod tenPow?1 =32

dbg:iteration 4:tenPow?1 = tenPow?1 / 10 =10
3
dbg:iteration 4:number?2 = number?2 mod tenPow?1 =2

dbg:iteration 5:tenPow?1 = tenPow?1 / 10 =1
2
dbg:iteration 5:number?2 = number?2 mod tenPow?1 =0
6


times directive at this point has immune to my debugging.
I will be glad to all who will improve my macro code.
Post 27 May 2014, 23:08
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.