"Words Used" changes from PIC to PIC


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185

    Cool "Words Used" changes from PIC to PIC

    Compiling a code for a PIC chip uses less or more words then compiling the same code for another PIC.

    For example, in terms of the words used, compiling a code for F877 is approx. 25% more then compiling the same code for F628A. I had 2500 words for F877 but 2043 words for F628A.

    May I have some information why this happens?

    Thanks
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default Memory usage

    When a PIC has to change the bank select register to access another section of code memory, ram, or a register, that takes another instruction to do so, depending on where in the memory map this particular register or instruction is located.
    So, if you've got code all spread out thru the memory map, or ram defined in a bunch of different locations, or are using registers in different banks, etc.etc. or doing all of the above a lot, you use an extra instruction almost each time.
    I found this out awhile back when I was using the '877 on a large program and I ran out of room.

    Try this little experiment:

    Take a look at your program, specifically the variables in your program. Count the number of times each variable is used, take the highest used variable and assign it to BANK 0. Keep doing that, going down thru the list from the most used to the least used and keep trying to assign them to BANK 0 until the compiler complains that you are out of memory space.

    Example:
    Use 'TEMP1 var byte BANK 0'
    instead of 'TEMP1 var byte'

    You should find that your total code space usage will go down as you assign the most used variables to BANK 0. The reason variables assigned to BANK 0 used less memory is because it only takes one instruction to address those variables, whereas variables in a different bank (usually 2 or 4) take a second instruction to set up the pointer to those variables.
    I did this with my mp3 player firmware a long time ago and found a savings of roughly 20% in code space.

    Hope that somewhat answers your question. If not, look in the 'memory organization' section of your particular PIC's datasheet.

    JDG

  3. #3
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    It's kind of an interesting subject that I'd like to see more info on.
    I've written some code for 16F84, 16F628, etc and the reported code size is apparently correct- but when I compile code for the 16F877 or 877A (using PM), I get all sorts of odd results - latest program reports 13,433 words used! (program compiles with no errors and runs fine).

    Arch

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Cool

    Hi JDG,

    Thanks for the information.

    I tried your little experiment using the most frequently used variables but it did not change anything for me (both for F877 and F628A, there is no change).
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default Program size

    Well, I suppose it might also have to do with how many variables you are using in the first place. If you use more than what will fit in BANK 0, then you'll never see a difference in code size.
    If your program is really short, try forcing all the variables to BANK 0, then try forcing them all to BANK 3 (or another BANK). You should see a difference.
    Again, if you read the memory organization section of the datasheet and compare that to how different areas of ram and code space are accessed, you'll see what I mean.
    By the way, none of this code space stuff works with the 18F series of PICs. Practically everything can be addressed with one instruction on those.
    JDG

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 11:00
  2. Replies: 67
    Last Post: - 8th December 2009, 03:27
  3. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 15:46
  4. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 22:01
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th March 2005, 00:14

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