Running Out of Programing Memory


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    970


    Did you find this post helpful? Yes | No

    Default

    One thing that will save you a lot of code is replacing repeated segments of code like for example - SEROUT ..... or LCDOUT. So, if you have a LCDOUT "Hello World" maybe 5 times in your code, it would be better to replace 4 of them with a gosub ShowHelloWorld and keep the LCDOUT "Hello World" in that subroutine.
    Last edited by Jerson; - 8th November 2009 at 03:34.

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    Jerson,

    Yes, I already use a lot of sub-routines.

    Melanie,

    Using the BANK0 next to the variables declarations didn't help. I think that I read somewhere that newer versions of PBP already take care of this BANK issue. However, moving sub-routines to the beginning of the program after the variables declaration help me free about 60 words.

    Ioannis,

    The link that you provided was very helpfull. I used in my program a lot of (with different variables all the time)

    Code:
    IF (VAR_0=0) AND (VAR_1=1) AND (VAR_2=2) AND (VAR_3=3) THEN
       ........
    ENDIF
    
    IF (VAR_0=0) OR (VAR_1=1) OR (VAR_2=2) OR (VAR_3=3) THEN
       ........
    ENDIF
    And according to the link that you posted you can save a lot of space by changing the above lines by

    Code:
    IF (VAR_0=0) THEN
       IF (VAR_1=1) THEN
          IF (VAR_2=2) THEN
             IF (VAR_3=3) THEN
                ........
             ENDIF
          ENDIF
       ENDIF
    ENDIF
    
    IF (VAR_0=0) THEN ........
    IF (VAR_1=1) THEN ........
    IF (VAR_2=2) THEN ........
    IF (VAR_3=3) THEN ........


    Well by using this technique I was able to go from 8118 words down to 7216 words. Enough to do what I need to finish my project. It would be nice to see an improved version of this link here in this forum. I'm sure that there are many techniques and tricks to save a lot of space that we don't know about.

    Robert

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default

    I am glad it helped.

    The best way to reduce size is to do it in ... assembly.

    Ioannis

  4. #4


    Did you find this post helpful? Yes | No

    Default Move ascii strings out to EEROM

    Each ASCII character included in a SEROUT, LCDOUT, DEBUG or SEROUT2 takes at least two characters in program memory for each ASCII character in the string.

    Keep any user prompts as terse as possible.

    HTH
    BrianT

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    This brings up an issue that I have long harped on.

    Unless you are building a huge quantity of something, where the cost of the coding can be amortized across a large number of units, ALWAYS

    Use an 18F part
    Use a part that has at least twice the codespace you need.

    And, if you want to know if you have exceeded any particular memory size, use

    Code:
    ASM
         ORG 0x1fcee        ; put your limit here
         nop
    ENDASM
    at the end of your program. The compiler will give you an error if you exceed the size given in the ORG statement.
    Charles Linquist

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    Hi all,

    Thank you all for your help. This post is an update for this thread. When giving the final touches to my program, I found out one more time that I was running out of programming memory space. Luckily, I was able to reduce the size of my program by almost 1K words . I don't know assembly so; this is how I did it.

    Before, I was using only one variable I that was declared as a word for all my FOR I = ... NEXT I loops and whenever I needed a counter I = I + 1.

    Code:
    I VAR WORD
    Sometimes the value of I went well over 255 but must of the times it didn't go over 255. So, I created a new variable J and declared it as a byte.

    Code:
    I VAR WORD
    J VAR BYTE
    I replaced J by I wherever it was possible and BINGO, the size of the program went down by almost 1K words.
    Again, Thank you all for your help.


    Robert

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default

    Also a 0 to x instead of 1 to x may help too in a for-next loop.

    Ioannis

Similar Threads

  1. fatal error out of memory (pbpw.exe)
    By hardcore in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 14th March 2010, 20:13
  2. Need the code to write to a memory
    By Hamlet in forum General
    Replies: 0
    Last Post: - 20th August 2007, 01:22
  3. Replies: 4
    Last Post: - 2nd March 2007, 07:12
  4. sample code for M25P32
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th January 2007, 03:37
  5. Use internal program memory like DATA memory
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th December 2006, 19:38

Members who have read this thread : 0

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