how to shrink code


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    If minimal code size is the goal, then PBP is a LOT of work.

    Reducing gosubs is not always the best rule, unless you are getting rid of the subs that were only added to make the code more "readable". If you can insert a few subroutines to eliminate duplicate code, they are very helpful.

    One thing to do is eliminate as many built-in basic commands as possible. For instance, hserout is very inefficient. You can manually load your values into the TXreg and save a lot of space. The ADCIN command is probably even worse.

  2. #2
    Join Date
    Feb 2005
    Posts
    67


    Did you find this post helpful? Yes | No

    Smile

    Hi and thanks everyone.

    Using a combination of Lookup and assembler

    the code is now 3768 !!!! beauty !

    I noticed that lookup can reduce code but can also
    increase code, so be carefull !

    thanks

    kind regards

    Peter
    Pete

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Peter1960 View Post
    ...

    I noticed that lookup can reduce code but can also
    increase code, so be carefull !..

    Peter

    Peter, it depends on the location of the LookUp statement in your program.

    Just do a little experiment by changing its location in the program.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    Peter, it depends on the location of the LookUp statement in your program.

    Just do a little experiment by changing its location in the program.
    A lot also has to do with how many elements you are looking up. It does not pay off until you are looking up more than just a few... 2-3, and it is a waste; a dozen and it saves a lot.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I tend to use internal EEPROM for that when at all possible.

    If you want how nasty we could shrink it... challenge us a little bit and post it here

    Who take he challenge? Darrel? Bruce? Melanie? Alain? Skimask? Anyone?
    Last edited by mister_e; - 24th January 2008 at 20:44.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    I tend to use internal EEPROM for that when at all possible.
    If you want how nasty we could shrink it... challenge us a little bit and post it here
    Who take he challenge? Darrel? Bruce? Melanie? Alain? Skimask? Anyone?
    I'm up...but I'm afraid all I'll get is spanked...

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e from Montreal, Canada
    I tend to use internal EEPROM for that when at all possible.

    If you want how nasty we could shrink it... challenge us a little bit and post it here

    Who take he challenge? Darrel? Bruce? Melanie? Alain? Skimask? Anyone?
    Steve,

    Do you mean a scan routine that will get an input variable, then scan EEPROM and provide an output variable?

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

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    depending which part of the message you refer. But yeah, when possible i replace LOOKUP by a READ ... depending what also on-board i may use an external EEPROM. I don't have any conventions. Since awhile all my projects are different. I just try to find the best compromise to reduce cost, pcb space etc etc.

    Code shrinking is a kind of funny challenge... Peter says he already shrink it and maybe he's still working on, i don't know. What i suggest to him, is to post his whole code here to see how much we could reduce it.

    Not a must, be as i said, that's fun. I know Darrel like that kind of thing
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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