Better code check before compile?


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    From manual
    Code:
    2.18 Line-Concatenation ( : )
    Multiple commands may be written on a single line using colon characters to tell PBP where to insert a "virtual" line break.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    I agree with peja089, the colon acts as a virtual line break.
    If more than a signle statement should execute as a result of the evaluation use IF-THEN-ENDIF.

    With that said... In section 5.35 of the manual they actually DO show the following as a valid example:
    Code:
    IF B0 <> 10 THEN B0 = B0 + 1: B1 = B1 - 1
    And in fact, when compiling the followong code for a 16F628 both the Test1 and Test2 routines results in the same assembly code
    Code:
    A VAR BYTE
    B VAR BYTE
    C VAR BYTE
    D VAR BYTE
    
    Test1:
    IF A = 12 THEN B = 2 : C = 3 :  D = 4
    
    Test2:
    IF A = 12 THEN
      B=2
      C=3
      D=4
    ENDIF
    Here's the resulting assembly (both versions looks identical to me (wasn't really expecting that to be honest):
    Code:
    _Test1
             clrwdt
             movf    _A,  W
             sublw   00Ch
             btfss   STATUS, Z
             goto    L00001
             movlw   low (002h)
             movwf   _B
             movlw   low (003h)
             movwf   _C
             movlw   low (004h)
             movwf   _D
    L00001
    _Test2
            clrwdt
            movf    _A,  W
            sublw   00Ch
            btfss   STATUS, Z
            goto    L00003
            movlw   low (002h)
            movwf   _B
            movlw   low (003h)
            movwf   _C
            movlw   low (004h)
            movwf   _D
    L00003
    That got me curious so I compiled both version of the original code
    Code:
    ticker VAR BYTE
    ard VAR BYTE
    atrig VAR BYTE
    
    Test1:
    if ticker>150 and ard<140 and atrig=0 then ticker=1: atrig=1
    
    Test2:
    if ticker>150 and ard<140 and atrig=0 then
      ticker=1
      atrig=1
    ENDIF
    And the resulting assebly (less library code) looks like this:
    Code:
    _Test1
            movf    _ticker, W
            movwf   R0
            movlw   low (096h)
            call    CMPGTB
            movwf   T1
            movf    _ard, W
            movwf   R0
            movlw   low (08Ch)
            call    CMPLTB
            movwf   T2
            movf    T1,  W
            movwf   FSR
            movf    T2,  W
            call    LAND
            movwf   T2
            movwf   T2   + 1
            movf    _atrig, W
            sublw   000h
            btfss   STATUS, Z
            movlw   -1
            xorlw   0ffh
            movwf   T3
            movf    T2,  W
            iorwf   T2  + 1, W
            movwf   FSR
            movf    T3,  W
            call    LAND
            movwf   T3
            movwf   T3   + 1
            clrwdt
            movf    T3,  W
            iorwf   (T3)  + 1, W
            btfsc   STATUS, Z
            goto    L00001
            movlw   low (001h)
            movwf   _ticker
            movlw   low (001h)
            movwf   _atrig
    L00001
    _Test2
            movf    _ticker, W
            movwf   R0
            movlw   low (096h)
            call    CMPGTB
            movwf   T1
            movf    _ard, W
            movwf   R0
            movlw   low (08Ch)
            call    CMPLTB
            movwf   T2
            movf    T1,  W
            movwf   FSR
            movf    T2,  W
            call    LAND
            movwf   T2
            movwf   T2   + 1
            movf    _atrig, W
            sublw   000h
            btfss   STATUS, Z
            movlw   -1
            xorlw   0ffh
            movwf   T3
            movf    T2,  W
            iorwf   T2  + 1, W
            movwf   FSR
            movf    T3,  W
            call    LAND
            movwf   T3
            movwf   T3   + 1
            clrwdt
            movf    T3,  W
            iorwf   (T3)  + 1, W
            btfsc   STATUS, Z
            goto    L00003
            movlw   low (001h)
            movwf   _ticker
            movlw   low (001h)
            movwf   _atrig
    L00003
    As far as I can see they are identical, meaning atrig will only get set to 1 if the evaulation is true. So I don't know what might be happening in CuriousOnes case because as far as I can see it IS working as CuriousOne expects - which I did NOT expect.

    /Henrik.

  3. #3
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Better code check before compile?

    Quote Originally Posted by HenrikOlsson View Post
    ... which I did NOT expect.
    /Henrik.
    Same here

Similar Threads

  1. Code check and refinement suggestions?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 31st July 2013, 02:37
  2. Replies: 4
    Last Post: - 24th January 2007, 22:20
  3. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  4. Can some one please check my code out thanks
    By Jhdgkss in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th February 2006, 08:19
  5. Code check (sorry)
    By barkerben in forum General
    Replies: 5
    Last Post: - 30th November 2004, 15:54

Members who have read this thread : 1

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