flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
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? |
|||
![]() |
|
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 |
|||
![]() |
|
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 |
|||
![]() |
|
l_inc 25 May 2014, 22:35
ProMiNick
Quote: in addition of display family macros Try to output the value (-1) shl 64 ![]() Quote: display_Hex not operate on neg values. Who may resolve this? 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 |
|||
![]() |
|
ProMiNick 26 May 2014, 17:01
Thanks I_inc. Your macros are that i was looking for.
|
|||
![]() |
|
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:
times directive at this point has immune to my debugging. I will be glad to all who will improve my macro code. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.