How much code space do PBP statements use.


Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default How much code space do PBP statements use.

    How much code would a code hog hog, if a code hog could hog code?

    Answer: All available Code Space.

    But sometimes, it's not enough.   "Just a few more words, that's all I need"

    So, how do you find out which parts of a program use the most code space?
    Here's one way.
    NOTE: This has been improved for MPASM users. See post#4
    Code:
    <font color="#008000"><b>ASM
    </b></font><font color="#0000FF"><b><i>;----------------------
    </i></b></font><font color="#000080">StartSize  macro  
    CodeStartAddress = $
        endm
        
    </font><font color="#0000FF"><b><i>;----------------------
    </i></b></font><font color="#000080">EndSize  macro  Name
    Name =  $ - CodeStartAddress
        endm
    </font><font color="#008000"><b>ENDASM</b></font>
    These 2 macros do NOT use any code space. They merely create "Symbols" in the assembler that indicate the size of the measured Code.

    To measure the size of any block of code, simply place an @ StartSize statement just before the code you want to measure. Then place a @ EndSize Name after the block of code and replace Name with something that you can easily remember.
    Code:
    <font color="#000080">@  StartSize
         </font><font color="#008000"><b>LCDOUT </b></font><b>$FE</b>,<b>1</b>,<font color="#FF0000">&quot;Hello World!&quot;
    </font><font color="#000080">@  EndSize  SizeOF_HelloWorld</font>
    This will create an entry in the Symbol Table called SizeOF_HelloWorld, and in this case it will be 0000002A, or 42 words.

    The Symbol table can be found at the bottom of the .lst file if you are using MPASM. Or, in the .SYM file if using PM

    There are 2 parts to how much space is used by PBP statements. The first part is the code added to the PBP system for any given Command. and, the second part is the code used by the statements themselves. &nbsp; For instance, the first time you use an LCDOUT statement, PBP will add approximately 107 words of code to the system, plus the 42 words for the statement itself, for a total of 149 words. If the exact same statement is used a second time, it will only add another 42 words.

    This approach will only measure the code size used by the statements themselves, not the code added to the system. The system code size can be determined by commenting out the statements being measured, and seeing how much difference there is in the total code size. Then subtract the previously measured size of the statements. What's left indicates how much system code was added.<hr>

    Let's say for instance that you were using a SELECT CASE structure, and you wanted to see if using a LOOKUP would save any space.

    Code:
    <font color="#000000"><b>row   </b><font color="#008000"><b>VAR  BYTE
    </b></font><b>temp  </b><font color="#008000"><b>VAR  BYTE
    
    </b></font><font color="#000080">@  StartSize
        </font><font color="#008000"><b>SELECT CASE </b></font><b>row
            </b><font color="#008000"><b>CASE </b></font><b>1 </b>: <b>temp </b>= <b>$80
            </b><font color="#008000"><b>CASE </b></font><b>2 </b>: <b>temp </b>= <b>$C0
            </b><font color="#008000"><b>CASE </b></font><b>3 </b>: <b>temp </b>= <b>$90
            </b><font color="#008000"><b>CASE </b></font><b>4 </b>: <b>temp </b>= <b>$D0
        </b><font color="#008000"><b>END SELECT
    </b></font><font color="#000080">@  EndSize sizeOF_CASE
    
    @  StartSize
        </font><font color="#008000"><b>LOOKUP </b></font><b>row</b>,[<b>$80</b>,<b>$80</b>,<b>$C0</b>,<b>$90</b>,<b>$D0</b>],<b>temp
    </b><font color="#000080">@  EndSize sizeOF_Lookup</font>
    The symbol table will now contain these 2 entries<pre>sizeOF_CASE 0000002D<br>sizeOF_Lookup 00000016
    </pre>
    Now it's easy to see that the SELECT CASE took 45 words, and the LOOKUP only used 22.<hr>

    To find out if any system code was added, write down the total words used by the program, in the above case it's 217. &nbsp;Then comment out the section in question and compile it again.
    Code:
    <font color="#000000"><b>row   </b><font color="#008000"><b>VAR  BYTE
    </b></font><b>temp  </b><font color="#008000"><b>VAR  BYTE
    
    </b></font><font color="#000080">@  StartSize
    </font><font color="#0000FF"><b><i>'    SELECT CASE row
    '        CASE 1 : temp = $80
    '        CASE 2 : temp = $C0
    '        CASE 3 : temp = $90
    '        CASE 4 : temp = $D0
    '    END SELECT
    </i></b></font><font color="#000080">@  EndSize sizeOF_CASE
    
    @  StartSize
        </font><font color="#008000"><b>LOOKUP </b></font><b>row</b>,[<b>$80</b>,<b>$80</b>,<b>$C0</b>,<b>$90</b>,<b>$D0</b>],<b>temp
    </b><font color="#000080">@  EndSize sizeOF_Lookup</font>
    After this compile, the total words used is 172. So the difference is 45 words. Since we've already determined that the statements themselves used 45 words, we now know that nothing was added to the PBP system.<hr>

    Now, get out there and put the "Squeeze" on some code.
    <br>
    Last edited by Darrel Taylor; - 19th September 2005 at 01:20.
    DT

Similar Threads

  1. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  2. Changing Swordfish code to PBP
    By Ron Marcus in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th April 2008, 01:28
  3. 4 Chanel Dmx512 ready assembly code to PBP ?
    By syscoder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 21st March 2007, 23:55
  4. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  5. Need more code space
    By ghutchison in forum General
    Replies: 1
    Last Post: - 12th February 2005, 20:54

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts