Subroutine placement - must they come first?


Closed Thread
Results 1 to 7 of 7

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Subroutine placement - must they come first?

    One good thing to remember about asm DATA, DA, DT...

    Recently I've messed a lot with the Nokia GLCD thing and while I added Strings, some could not be properly displayed, code went to lalaLand. The reason is like Bruce said... page boundary. In the end my macro just needed a simple modification... from something like
    Code:
    MyWhateverString Macro Str
               local STRStart, STREnd
               GOTO STREnd
    STRStart
               DT Str
    STREnd
               MOVE?CW STRStart, _WhateverAddrVar
               L?CALL _MainSub
               ENDM
    To
    Code:
    MyWhateverString Macro Str
               local STRStart, STREnd
               L?GOTO STREnd
    STRStart
               DT Str
    STREnd
               MOVE?CW STRStart, _WhateverAddrVar
               L?CALL _MainSub
          ENDM
    problem solved
    Last edited by mister_e; - 13th July 2011 at 18:11.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default Re: Subroutine placement - must they come first?

    Quote Originally Posted by mister_e View Post
    One good thing to remember about asm DATA, DA, DT...

    Recently I've messed a lot with the Nokia GLCD thing and while I added Strings, some could not be properly displayed, code went to lalaLand.
    Oh Steve, that was Your code I saw . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default Re: Subroutine placement - must they come first?

    A snip of...few hundred lines....
    Steve

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

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Subroutine placement - must they come first?

    My ignorance is on clear display here so please be gentle.
    I have a system of two PIC16F88 and three 18F4620 which all chatter amongst themselves over a multiwire parallel bus. Some of the code takes up over 63000 bytes on a PIC 18F4620.
    Currently all the subroutines are placed after the hardware and variable declarations. I would like to have the subroutines at the bottom of the code if possible for simpler reading.

    I recall some earlier (PBP2.xx?) comments that subroutines should be at the top of the program but is there any more explicit advise for the 16F88 or the 18F4620. Bruce's comments pass over my head.

    Cheers
    BrianT

  5. #5
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Subroutine placement - must they come first?

    You can put subroutines anywhere you like and PBP worries about page swaps for you. If, however, you have real time or compiled code size issues, putting them at the beginning can help optimize. There are also special issues when crossing page boundaries that PBP *usually" takes care of - a notable exception is mentioned above.

    I always put my subroutines at the end for readability. in 99% of cases this is fine.
    These days I like to use 18F parts which tend to have a better sense of humour about these things, as well as usually being faster and having more memory. (at slightly highter cost)

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts