Changing position of program code


Closed Thread
Results 1 to 18 of 18

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    So in this case, where do we put the subs then?

    Based on what criteria do we arrange the subs?


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

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Hi Sayzer. Well, now there is no official directive as to where is better placed a sub. According to old practice, on top. But this does not affect in any way the execution.

    I only pointed out that if one has 5 sub's for example, and have different sizes, rearranging the order of them is affecting the final code size. I think is because a bigger sub might fall between two pages while others won't.

    After a little experimenting you can find that your code might reduce up to 20% or more! Also if you change your variables to be placed on BANK0 also may help. Especially if there are arrays in the program. I had a program reduced from 7540 bytes to 6200 using the above!

    Ioannis

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink THE Basic weakness ...

    Hi, Sayzer

    You meet here The big Basic Programmer's lack of project definition ...

    Basic enables you lots of jumps and come back ... But the first thing is to write a neat logical organigram ...

    Like It was to be done with "old dinausaurs " programming langages like Fortran ...

    So, the thing to do is put the job in a correct order to have the minimum GOTOs and GOSUBs ...

    No so easy ... when the project grows more and more !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Just a note: what I described at #13 has nothing to do with GOTO's. Just the order of the sub's. If this is going on top of the other has an immediate impact on code size produced.

    Ioannis

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Cool ahhhh

    Hi Ioannis,acetronics,
    I knew aerostar had a reason, now I know why. I learned something again today! Thanks,
    JS


    edit
    FORTRAN ? Now we're talkin OLD I remember studying my dad's fortran manuals in 1968? I think Dr. Peabody used that to program the wayback machine!

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics
    Hi, Sayzer

    You meet here The big Basic Programmer's lack of project definition ...

    Basic enables you lots of jumps and come back ... But the first thing is to write a neat logical organigram ...

    Like It was to be done with "old dinausaurs " programming langages like Fortran ...

    So, the thing to do is put the job in a correct order to have the minimum GOTOs and GOSUBs ...

    No so easy ... when the project grows more and more !!!

    Alain

    I always thought that programming structure addresses a programmer who is looking at the code from outside. So that when you write a code, another programmer from outside can understand your coding and logic relatively easier.

    If you write a code that is mixed all over, a new comer will not understand the logic flow.

    But, despite all, now, I learn that the structure also has a direct effect on the code size.

    I just made some tests, moved the subs around in a code.
    The code size indeed drops.


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

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


    Did you find this post helpful? Yes | No

    Default

    I know what I will suggest is not much of a help, but generally the big sub's is better to be placed on top of each memory page. If you cannot find how long a sub may take, then compile it in a new program file, after compilation check the length and move the sub to a better position at the final program.

    Then the rest of the page can be filled with a smaller sub.

    If anyone has a better suggestion, please, one step forward.

    Ioannis

Similar Threads

  1. DS1307 and a LED array, need ideas
    By peu in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 30th December 2009, 18:45
  2. Problem runing my code
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 1st December 2009, 20:36
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. Code: Why is this code greater than 2000 words?
    By DrDreas in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 1st June 2007, 19:51
  5. Replies: 7
    Last Post: - 25th July 2006, 15:11

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