Using "If then" and "and" together


Results 1 to 7 of 7

Threaded View

  1. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: Using "If then" and "and" together

    Using PBP 2.60C, MCSP v2.2.1.1, MPASM v5.46, PIC 18F46K22.

    62 bytes:
    Code:
    @   __CONFIG    _CONFIG1H, _FOSC_HSHP_1H & _PLLCFG_OFF_1H & _PRICLKEN_OFF_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    @   __CONFIG    _CONFIG2L, _PWRTEN_ON_2L & _BOREN_SBORDIS_2L & _BORV_285_2L
    @   __CONFIG    _CONFIG2H, _WDTEN_OFF_2H
    @   __CONFIG    _CONFIG3H, _PBADEN_OFF_3H & _HFOFST_OFF_3H & _MCLRE_EXTMCLR_3H
    @   __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    DEFINE OSC 20
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0
    ANSELD = 0
    ANSELE = 0
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %00000000
    TRISD = %10000000
    TRISE = %00000000
    
    CODE_ONE        VAR PortB.1
    CODE_TWO        VAR PortB.2
    CODE_THREE      VAR PortB.3
    CODE_FOUR       VAR PortB.4
    CODE_FIVE       VAR PortB.5
    
      IF CODE_ONE = 13 THEN
        IF CODE_TWO = 13 THEN  'With an oh
          IF CODE_THREE = 16 THEN
            IF CODE_FOUR = 21 THEN
              IF CODE_FIVE = 32 THEN
                'Correct code
              ENDIF
            ENDIF
          ENDIF
        ENDIF
      ENDIF
    END
    138 bytes:
    Code:
    @   __CONFIG    _CONFIG1H, _FOSC_HSHP_1H & _PLLCFG_OFF_1H & _PRICLKEN_OFF_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    @   __CONFIG    _CONFIG2L, _PWRTEN_ON_2L & _BOREN_SBORDIS_2L & _BORV_285_2L
    @   __CONFIG    _CONFIG2H, _WDTEN_OFF_2H
    @   __CONFIG    _CONFIG3H, _PBADEN_OFF_3H & _HFOFST_OFF_3H & _MCLRE_EXTMCLR_3H
    @   __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    DEFINE OSC 20
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0
    ANSELD = 0
    ANSELE = 0
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %00000000
    TRISD = %10000000
    TRISE = %00000000
    
    CODE_ONE        VAR PortB.1
    CODE_TWO        VAR PortB.2
    CODE_THREE      VAR PortB.3
    CODE_FOUR       VAR PortB.4
    CODE_FIVE       VAR PortB.5
    
      IF CODE_ONE = 13 and CODE_TWO = 13 and CODE_THREE = 16 and CODE_FOUR = 21 and CODE_FIVE = 32 THEN
        'Correct code
      ENDIF
    END
    I know, Port be is defined as output and used as input (noticed after test), but that has no impact on test significance.

    More than twice as big using single IF, nested IF is definitely more efficient. I remember reading about that somewhere recently too, can't remember where.

    Robert
    Last edited by Demon; - 24th September 2012 at 15:44.

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