; -------------------------------------------------------------------------------- ; @Title: Count number of memory words that have a certain value ; @Description: ; Counts the number of memory words that have the value as passed to the script ; Usage: DO wordcount.cmm ; E.g.: DO wordcount.cmm D:0x40000000--0x4000FFFF LONG 0xAAAAAAAA ; @Keywords: practice ; @Author: rweiss ; @Copyright: (C) 1989-2017 Lauterbach GmbH, licensed for use with TRACE32(R) only ; -------------------------------------------------------------------------------- ; $Id: wordcount.cmm 11432 2017-09-27 10:44:18Z rweiss $ LOCAL &range &width &value LOCAL &addr &end &words &count &width &bytewidth ( ON ERROR GOTO syntaxerror ENTRY &range &width &value &width=STRing.LoWeR("&width") IF "&width"=="quad" &bytewidth=8 ELSE IF "&width"=="long" &bytewidth=4 ELSE IF "&width"=="word" &bytewidth=2 ELSE IF "&width"=="byte" &bytewidth=1 ELSE GOTO syntaxerror &addr=ADDRESS.OFFSET(ADDRESS.RANGE.BEGIN(&range))&(0-&bytewidth) &end=(ADDRESS.OFFSET(ADDRESS.RANGE.END(&range))&(0-&bytewidth))+(&bytewidth-1) &words=((&end-&addr)/&bytewidth)+1 ) Data.COPY &range VM:&addr /&width LOCAL &valuecount &valuecount=0 RePeat &words ( IF Data.&width(VM:&addr)==&value &valuecount=&valuecount+1 &addr=&addr+&bytewidth ) LOCAL &res1 &res1 &res3 &res1="Searched &value in "+FORMAT.DECIMAL(1.,&words)+" &width words:" &res2="Value found in "+FORMAT.DECIMAL(1.,&valuecount)+" &width words ("+FORMAT.DECIMAL(1.,(&valuecount*100.)/&words)+"%)" &res3="Other value in "+FORMAT.DECIMAL(1.,&words-&valuecount)+" &width words ("+FORMAT.DECIMAL(1.,100.-((&valuecount*100.)/&words))+"%)" DIALOG.OK "&res1"+CONV.CHAR(0x0A)+"&res2"+CONV.CHAR(0x0A)+"&res3" ENDDO syntaxerror: DIALOG.OK "Syntax:"+CONV.CHAR(0x0A)+" DO wordcount.cmm "+CONV.CHAR(0x0A)+"E.g."+CONV.CHAR(0x0A)+" DO wordcount.cmm D:0x40000000--0x4000FFFF LONG 0xAAAAAAAA" ENDDO