I'm using MPLAB X IDE v4.20 to compile the following code:

            #INCLUDE <P18F4321.INC>
            CONFIG OSC=INTIO2 ;     Select internal oscillator
            CONFIG WDT=OFF ;    Watchdog Timer OFF
            CONFIG LVP=OFF ;    Low Voltage Programming OFF
            CONFIG BOR=OFF ;    Brown Out Reset OFF
            BSF TRISC,TRISC1;   Configure bit 1 of Port C as input
            BCF TRISC,TRISC0;   Configure bit 0 of Port C as output
            BSF TRISD,TRISD1;   Configure bit 1 of Port D as input
            BCF TRISD,TRISD0;   Configure bit 0 of Port D as output 
    BACK    RRNCF PORTC,F;      Align data in Port C and output to LED
            RRNCF PORTD,F;      Align data in Port D and output to LED
            BRA BACK

and I get the following error message for all the lines starting on BSF TRISC,TRISC1; to BCF TRISD,TRISD0; and also for the line BRA BACK,

"Error[152] C:\ECE\ECE3301LRAFI\LAB4.X\LAB4RAFI.ASM 12 : Executable code and data must be defined in an appropriate section".

So it doesn't compile because of that.

Now, what it intrigues me is that if I compile it in MPLAB IDE v8.50 it does compile without any errors. The reason I was doing it in MPLAB IDE v8.50 is because my professor uses it for the labs, but he uses PICKit 3; however, I have a PICKit4, and MPLAB IDE v8.50 doesn't seem to be compatible with it. So I'm using MPLAB IDE v4.20. I know that it has to do with keywords or something like that, but I don't really understand. Do I need an ORG to compile even if I don't need it for the actual code? Any help will be appreciated. By the way, the experiment is really simple: "to perform a simple I/O experiment by interfacing DIP switches and LEDs to the PIC18F4321 using Microchip’s MPLAB assembler and PICKit3." He said that we can use either PICKit3 or PICKit4.


Do I need an ORG to compile even if I don't need it for the actual code?

Yes, you need an ORG directive to tell the assembler where to put your code (the assembler itself may not need it, but when invoked via MPLABX it does).

Since code execution starts at memory location 0 on reset, you should put

  ORG 0

immediately before the first instruction.

This should work for your simple program, but realize that location 0x0008 is the entry point for the high priority ISR (Interrupt Service Routine), and 0x0018 is the low priority ISR. Any code longer than 8 bytes that uses interrupts will have to jump over the ISR code, like this:-

    ORG 0
    BRA  startup

    ORG 0x008
    ; high priority ISR code 

    ORG 0x018
    ; low priority ISR code

    ; your code here      

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.