Shop OBEX P1 Docs P2 Docs Learn Events
Conserving eeprom space — Parallax Forums

Conserving eeprom space

LloydsLloyds Posts: 75
edited 2010-09-01 05:45 in BASIC Stamp
Hi,
I am running out of eeprom space on the p40 and am working on paring the usage down. I apologize for asking what I'm sure has been covered before, but I am looking for easy ways to free up some space.

It looks like any "quoted" messages, including "spaces," in DEBUG and LCDOUT take up lots of room. Fixing those helped a lot. Using the special control characters in DEBUG helped too.

Turning some of the "cut and paste" code into subroutines, helped.

It seems like any number 'comments do not affect eeprom space.

What about the length of variable names, or the length of pin assignment names?

What about using hex vs decimal vs binary numbers in the code?

Any other easy ways?

I'm not ready to dive into the program slot method yet.
Thanks for any suggestions,
Lloyd

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-30 07:54
    Variable names, labels, pin names, comments are all stripped out by the PBasic compiler and take no space in the compiled program. All numeric constants are converted to numbers regardless of how they're written and these are further compressed so values in the range 0-255 take less room than values in the range 256-65535. Some constants (like 0 and 1) have special compact forms.
  • bill190bill190 Posts: 769
    edited 2010-08-30 09:17
    Text messages and Data (array/constants) will take up space.

    Then I use subroutines for 2 different things...

    One is to make the code more clear an understandable. I stick something which does a specific task in a subroutine and give it a name which clearly indicates what it does.

    Or code which is used again and again, I create one subroutine to do that.

    For code which is used many times, it will save space to stick it in a subroutine. However for code which is used only once, it takes a bit more space to stick it in a subroutine. So if the code is used only once, don't stick it in a subroutine, then that will save space.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-08-30 13:23
    If you still have necessary messages for DEBUG and LCDOUT, you already know it eats up space fast (14 bits per character) and it pays to move it to DATA statements (8 bits per character, plus a reader routine).

    It's really not that hard to dive into a new slot where an expanse of untapped eeprom awaits you. A good way to start is to move the text to its own slot. Then your main slot only needs a method to pull that text out.

    Here are demo routines that do that. A main routine for slot 0, and an indexed array of messages in slot 1.

    ' {$STAMP BS2pe, "slotDataDemo_1.bpe"}
    ' {$PBASIC 2.5}
    
    index VAR BYTE
    char VAR BYTE
    pointer VAR WORD
    
    FOR index=0 TO 3   ' demo, read and show 4 messages
      GOSUB Slot_text_reader
    NEXT
    END
    
    Slot_text_reader:
    ' enter with index 0,1,2,3... of the message in slot 1
      STORE 1   ' slot 1 DATA
      READ index*2, WORD pointer  ' points to start of message
      DEBUG DEC pointer,32   ' show the pointer for good measure
      PAUSE 256
      DO
        READ pointer,char    ' print the null terminated message
        IF char THEN DEBUG char ELSE EXIT
        pointer = pointer+1
      LOOP
      STORE 0   ' set the data pointer back to slot zero
      PAUSE 1024
      RETURN
    
    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    
    slot1_text:   ' this is slot 1 program
    indices DATA WORD string0, WORD string1, WORD string2, WORD string3 ',...
    string0  DATA "This is a test...",CR,0 ' null terminated strings
    string1  DATA "Seen a good movie?",CR,0
    string2  DATA "The windspeed is ",CR,0
    string3  DATA "and so on...",CR,0
    
  • LloydsLloyds Posts: 75
    edited 2010-08-31 07:29
    Thanks everyone for the tips.
    I managed to par things down and use the subroutines this time, and all is functioning well.

    But I see that I'll have to use the more advanced techniques before I can flesh out the documentation with a non-abbreviated compliment of LCD menus and debug screens.

    Thanks again,
    Lloyd
  • APSpijkermanAPSpijkerman Posts: 32
    edited 2010-09-01 05:45
    I noticed that this:

    if cnt <> 50 then skip50
    ...
    skip50:

    takes less space then this:

    IF cnt = 50 THEN
    ...
    ENDIF

    ???
Sign In or Register to comment.