IF/ELSE/ENDIF Example

MPASM Assembler

IF/ELSE/ENDIF Example

Directives highlighted in this example are:

  • else
  • endif
  • Program Functional Description

    This program demonstrates the utility of IF, ELSE and ENDIF assembly directives.

    Commented Code Listing

    list p=16f877 ;Select the device.

    #include <p16f877.inc> ;Include standard header file

    ;for the selected device.

    variable config ;variable used to define

    ;required configuration of

    ;PORTA & PORTB

    config set D'1'

    RST CODE H'0' ;The code section named RST

    ;is placed at H'0'. The

    ;instruction 'goto start' is

    ;placed in code section RST

    goto start ;Jumps to the location labelled

    ;'start'.

    INTRT CODE H'4' ;The code section named INTRT is

    ;placed at H'4'. The instruction

    ;'goto service_int' is placed in

    ;code section INTRT.

    goto service_int ;Jumps to the location labelled

    ;'service_int'.

    PGM CODE ;This is the begining of the code

    ;section named PGM. It is a

    ;relocatable code section since

    ;no absolute address is given

    ;along with directive 'CODE'.

    start

    if config==H'0' ;If config==H'0' is true,

    clrw ;assemble the mnemonics up to

    movwf TRISA ;the directive 'else'.

    movlw H'ff'

    movwf TRISB

    else

    clrw ;If config==H'0' is false,

    movwf TRISB ;assemble the mnemonics up to

    movlw H'ff' ;the directive 'endif'.

    movwf TRISA

    endif

    goto $

    service_int

    retfie

    end


    Microchip Technology Inc.
    Microchip's Web Site
    Voice: (480) 792-7200
    Fax: (480) 899-9210
    Microchip's E-mail Address
    PreviousNext