--- This is a test - only visible to admins ---
--- advertisement may go here ---
  • Pic® Basic


  • Writing compact code

    by Tim Box

    There will nearly always come a time when the code space in your PIC® runs short and you start to think about making some savings. Unfortunately this is not the best time to start thinking about it.

    You really need to think small from the start. So how is this done? Like most things to get good at it you need practice, but here is a simple example to start you in the right direction

    Variables

    Every time you use a variable either in a decision-making or a maths statement the code taken is proportional to the variable used.

    Take these examples

    IF VARA = VARB THEN GOTO CODE_A

    VARA = VARB * VARC

    With the Vars as BYTE’s 6 words and 36 words
    With the Vars as WORD’s 10 words and 40 words
    With the Vars as DWORD’s 18 words and 65 words

    As you can see it pays to keep the numbers small.