View Single Post
  #11   Spotlight this post!  
Unread 09-03-2004, 00:11
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Re: Do you write functions for your code?

Quote:
Originally Posted by KenWittlief
actaully, the SW we are creating for these machines is realtime embedded code

remember that the C compiler will convert your code into assembly code, and from that into machine code

breaking your code up into many little functions makes it look nice, but it actually takes longer for it to run, and takes up more code space, because the function calls are actully jumps in assembly code

its shorter and faster to have sequential code all in one routine that simply falls through to the next statement.

not that we really have to be concerned with optimizing our code for size or speed.

well wait, I have seen some people posting that they have used up all the available code space this year - so maybe some of us got a little carried away with the functions :^)
On processors without big pipelines (x86, etc have big pipes, especially Intels), function calls are relatively cheap, especially for FIRST robots. The big thing you have to watch out for is stack space, as the PIC can only natively handle 16 nested function calls. There are ways around this limit (like writing your own stack handler), but they tend to be messy and ridiculously hard to debug in addition to being a pain in the neck to write if you've never done it before. Anyways, just be careful that you don't have calls 16-levels deep and everything should be just fine.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php