Multiple if then optimization


Closed Thread
Results 1 to 36 of 36

Hybrid View

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


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by skimask View Post
    13 LINES!

    Hi, Ski

    That's way too hard for my old eyes !!! Lol ...

    at second look ... I've seen that somewhere before, but Where ??? ...

    Alain
    Last edited by Acetronics2; - 3rd March 2008 at 15:46.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Ski
    That's way too hard for my old eyes !!! Lol ...
    at second look ... I've seen that somewhere before, but Where ??? ...
    Alain
    Might even be a few words shorter on code!
    Or at least a few colons longer.

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


    Did you find this post helpful? Yes | No

    Default

    13 lines is not the case ;

    But, it is only 2 words smaller then Alain's.

    Come on Ski, saved 2 words only ???


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

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    13 lines is not the case ;
    But, it is only 2 words smaller then Alain's.
    Come on Ski, saved 2 words only ???

    -----------------
    It's monday! What'd you expect?
    Wait 'till DT comes online...
    Figure maybe down to...what...25 words total?

  5. #5
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Talking Test Result

    Welcome dear ladies and gentlemen to todays code shrinking contest!

    Now I testet all 3 programms and have to tell the outcome:

    1.: Dear Mr. Sayzer, theres a small bug in your code, it shows only "Too High" or "Too Low"

    2.: Dear Mr. Acetronic: Excellent work, runs flawlessly.

    3.: Dear Mr. skimask: Full OK also !

    Applause to all three contestants.

    Besides: tons (ok kilos) of learning opportunities for me.

    Thanks you Gurus!

    Mugel

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    It's monday! What'd you expect?
    Wait 'till DT comes online...
    Figure maybe down to...what...25 words total?
    Thanks for the vote of confidence ski.

    But sadly, all I could muster was a slim 335 words

    Code:
    <font color="#000000"><b>CMCON </b>= <font color="#800000"><b>7                </b></font><font color="#0000FF"><b><i>' Disable Comparators
    
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>DEBUG_BAUD </b><font color="#800000"><b>2400   </b></font><font color="#0000FF"><b><i>'Debug baud rate 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>DEBUGIN_REG PORTB </b><font color="#0000FF"><b><i>'Debugin pin port 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>DEBUGIN_BIT </b><font color="#800000"><b>0     </b></font><font color="#0000FF"><b><i>'Debugin pin bit 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>DEBUGIN_MODE </b><font color="#800000"><b>1    </b></font><font color="#0000FF"><b><i>'Debugin mode: 0 = True, 1 = Inverted 
    
    </i></b></font><b>Uin       </b><font color="#008000"><b>VAR WORD
    </b></font><b>B0        </b><font color="#008000"><b>VAR BYTE 
    </b></font><b>BarCount  </b><font color="#008000"><b>VAR BYTE
    </b></font><b>BarValue  </b><font color="#008000"><b>VAR WORD
    </b></font><b>MsgAddr   </b><font color="#008000"><b>VAR WORD
    </b></font><b>Carry     </b><font color="#008000"><b>VAR </b></font><b>STATUS</b>.<font color="#800000"><b>0        </b></font><font color="#0000FF"><b><i>; Hardware carry flag
    
    </i></b></font><font color="#008000"><b>GOTO </b></font><b>Main                     </b><font color="#0000FF"><b><i>; Jump over data
    ;=============================================================================
     </i></b></font><b>BarSteps</b>:  <b>POKECODE   </b><font color="#800000"><b>10</b></font>,<font color="#800000"><b>15</b></font>,<font color="#800000"><b>19</b></font>,<font color="#800000"><b>24</b></font>,<font color="#800000"><b>29</b></font>,<font color="#800000"><b>34</b></font>,<font color="#800000"><b>43</b></font>,<font color="#800000"><b>53</b></font>,<font color="#800000"><b>62</b></font>,<font color="#800000"><b>72</b></font>,<font color="#800000"><b>81</b></font>,<font color="#800000"><b>86</b></font>,<font color="#800000"><b>91</b></font>,<font color="#800000"><b>96</b></font>,<font color="#800000"><b>100</b></font>,<font color="#800000"><b>105
    </b></font><b>_BarSteps   </b><font color="#008000"><b>CON </b></font><b>EXT           </b><font color="#0000FF"><b><i>; create a PBP constant that points to the Table
    
     </i></b></font><b>TooLow</b>:  <b>POKECODE </b><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>1</b></font>,<font color="#FF0000">&quot;TOO LOW &quot;</font>,<font color="#800000"><b>0
    </b></font><b>_TooLow   </b><font color="#008000"><b>CON </b></font><b>EXT             </b><font color="#0000FF"><b><i>; PBP constant pointing to the &quot;Too Low &quot; string
      
     </i></b></font><b>TooRich</b>: <b>POKECODE </b><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>$C0</b></font>,<font color="#FF0000">&quot;TOO RICH&quot;</font>,<font color="#800000"><b>0
    </b></font><b>_TooRich  </b><font color="#008000"><b>CON </b></font><b>EXT             </b><font color="#0000FF"><b><i>; PBP constant pointing to the &quot;Too Rich&quot; string
      
    </i></b></font><b>FlashSize </b><font color="#008000"><b>CON </b></font><b>EXT
    </b><font color="#008000"><b>ASM
       </b></font><font color="#000080">ifdef BSR
    FlashSize = 2                 </font><font color="#0000FF"><b><i>; 18F has byte addressing (2)
       </i></b></font><font color="#000080">else
    FlashSize = 1                 </font><font color="#0000FF"><b><i>; 12F/16F has words (1)
       </i></b></font><font color="#000080">endif
    </font><font color="#008000"><b>ENDASM
    
    </b></font><b>MidChar   </b><font color="#008000"><b>CON </b></font><b>EXT             </b><font color="#0000FF"><b><i>; MidChar is the border between
    </i></b></font><font color="#000080">@MidChar = 8 * FlashSize      </font><font color="#0000FF"><b><i>; 8 char segments of the 1x16 LCD being used
    
    ;=============================================================================
    </i></b></font><b>Main</b>:
        <font color="#008000"><b>DEBUGIN </b></font>[<b>Uin</b>.<b>LowByte</b>]     <font color="#0000FF"><b><i>; Serial Input
        </i></b></font><b>Uin </b>=  <b>Uin </b>*/ <font color="#800000"><b>124         </b></font><font color="#0000FF"><b><i>; same as (* 100 / 207)
        </i></b></font><font color="#008000"><b>LCDOUT </b></font><font color="#800000"><b>$FE</b></font>, <font color="#800000"><b>2             </b></font><font color="#0000FF"><b><i>; LCD Home Cursor
    
        </i></b></font><font color="#008000"><b>FOR </b></font><b>BarCount </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>TO </b></font>(<font color="#800000"><b>15 </b></font>* <b>FlashSize</b>) <font color="#008000"><b>STEP </b></font><b>FlashSize
            </b><font color="#008000"><b>IF </b></font>(<b>BarCount </b>= <b>MidChar</b>) <font color="#008000"><b>THEN LCDOUT </b></font><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>$C0  </b></font><font color="#0000FF"><b><i>; Second half of 1x16 LCD
            </i></b></font><b>PEEKCODE </b>(<b>_BarSteps</b>+<b>BarCount</b>),<b>BarValue       </b><font color="#0000FF"><b><i>; Get BarValue from Table
            </i></b></font><b>R0</b>.<b>LowByte </b>= <b>Uin</b>.<b>LowByte </b>- <b>BarValue
            </b><font color="#008000"><b>IF </b></font><b>Carry </b><font color="#008000"><b>THEN                                </b></font><font color="#0000FF"><b><i>; Uin &gt;= BarValue
                </i></b></font><font color="#008000"><b>LCDOUT </b></font><font color="#800000"><b>255                               </b></font><font color="#0000FF"><b><i>;  show a Full char
            </i></b></font><font color="#008000"><b>ELSE                                         </b></font><font color="#0000FF"><b><i>; Uin &lt; BarValue
                </i></b></font><font color="#008000"><b>LCDOUT </b></font><font color="#FF0000">&quot; &quot;                               </font><font color="#0000FF"><b><i>;  show a blank
            </i></b></font><font color="#008000"><b>ENDIF
        NEXT </b></font><b>BarCount
        
        R0</b>.<b>LowByte </b>= <b>Uin</b>.<b>LowByte </b>- <font color="#800000"><b>10                    </b></font><font color="#0000FF"><b><i>; if Uin &lt; 10
        </i></b></font><font color="#008000"><b>IF </b></font>!<b>Carry </b><font color="#008000"><b>THEN </b></font><b>MsgAddr </b>= <b>_TooLow </b>: <font color="#008000"><b>GOSUB </b></font><b>ShowMsg
    
        R0</b>.<b>LowByte </b>= <b>Uin</b>.<b>LowByte </b>+ <font color="#800000"><b>145                   </b></font><font color="#0000FF"><b><i>; if Uin &gt; 110
        </i></b></font><font color="#008000"><b>IF </b></font><b>Carry </b><font color="#008000"><b>THEN </b></font><b>MsgAddr </b>= <b>_TooRich </b>: <font color="#008000"><b>GOSUB </b></font><b>ShowMsg
    </b><font color="#008000"><b>GOTO </b></font><b>Main
    
    </b><font color="#0000FF"><b><i>;=============================================================================
    </i></b></font><b>ShowMsg</b>:
        <b>PEEKCODE MsgAddr</b>, <b>B0
        </b><font color="#008000"><b>IF </b></font><b>B0 </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>THEN RETURN
        LCDOUT </b></font><b>B0
        MsgAddr </b>= <b>MsgAddr </b>+ <b>FlashSize
    </b><font color="#008000"><b>GOTO </b></font><b>ShowMsg
    </b>
    cheers,
    DT

  7. #7
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Smile Its Guru time

    Hi Darrel,

    looks impressive to me like a motorcycle to a small boy.....

    Whats this command:

    Uin = Uin */ 124 ; same as (* 100 / 207)

    |
    |
    |
    the above means two mathematic orders in one? something like shifting bits?

    there would be a small mistake but thats totally acceptable because the bargraph is that crude which is really fine enough.

    will test that of course although there should be no need.....

    regards

    Mugel

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The */ operator first multiplies the 2 values (Uin * 124).
    Then it discards the low byte, and returns the rest.
    So effectively, it divides the result by 256, without having to do the divide part.

    100 / 207 = 0.48309178
    124 / 256 = 0.484375 ; not exact, but pretty close

    You're correct that there are small differences between the 2 formulas, but the error is less than +/- 1. And, you will never see a difference with the resolution of a 16 block bargraph.

    And, there probably is a need to test it.
    I was using a 16F877 with a 4x20 LCD. Could have missed something for your 16F628A and 1x16 LCD.
    <br>
    DT

Similar Threads

  1. Multiple PICS from Same Crystal?
    By WOZZY-2010 in forum General
    Replies: 2
    Last Post: - 6th February 2010, 15:18
  2. Multiple analog inputs ?
    By rngd in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 25th February 2008, 15:13
  3. Multiple PIC programming
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 7th May 2007, 23:47
  4. Multiple PIC's with 1 crystal
    By puma in forum Schematics
    Replies: 11
    Last Post: - 20th March 2007, 17:02
  5. Multiple IR LEDs from 1 port using transistor
    By belpe123 in forum General
    Replies: 3
    Last Post: - 20th May 2005, 22:07

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