1
\$\begingroup\$

I'm beginner to Mplab and microController programing.i'm following a pic book .basically my program is a led turn on and off program .I'm using mplabx-v2.10 .this is not my complete code.however the error comes from line

BSF STATUS, 5

my code

STATUS EQU 03H
TRISA EQU 85H
PORTA EQU 05H

    BSF STATUS, 5

    END

the error is

Error[152]   C:\USERS\MADHAWAX\MPLABXPROJECTS\P-STAR1.X\NEWASMTEMPLATE1.ASM 6 : Executable code and data must be defined in an appropriate section

a snapshot of error

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

You need to separate the data and code with appropriate keywords. So, for example, you start off with some declaration of the PIC type and any included files:

; beginning of source
list    p=16F684
#include <p16F684.inc>

Next, you can declare variables in a data section (this is just a generic example):

    ; declaring variables
GENVAR  UDATA           ; general variables
myvar1  res 1       ; one byte
myvar2  res 2       ; two bytes

Normally, you then start the code section, using the keyword CODE, and add a goto from the reset vector (where the processor starts executing):

    ; start of code (reset vector)
RESET   CODE    0x0000      ; processor reset vector
    goto    start

Then, you declare any further CODE sections, for example:

    ; main program
MAIN    CODE

start
    ; e.g. configure ports
    banksel TRISA       ; configure PORTA as all o/p
    clrf    TRISA

    ; main loop
main_loop
    ; do stuff
    ;    "

    ; repeat forever
    goto    main_loop

    ; mandatory terminator
    END

I think your problem is that you have started writing code without declaring a CODE section.

EDIT Just fixing your code by adding the CODE keyword and the initial jump from the reset vector compiles fine:

asm

You also need to make sure you respect the necessary indents/initial spaces in code lines so that they are not mistaken for labels. Your first block of code (under MAIN) was not indented, so also caused errors.

\$\endgroup\$
3
  • \$\begingroup\$ tnx.my assemble code i taken from a book is here drive.google.com/file/d/0BzmWcy_weZw2V1NDdFpaODk0TlU/… can you show me how it should be corrected \$\endgroup\$
    – Fast Snail
    Commented Mar 29, 2015 at 20:15
  • \$\begingroup\$ @FastSnail Ok, just this once - see updated answer. \$\endgroup\$ Commented Mar 30, 2015 at 4:46
  • \$\begingroup\$ ok i got it.tnx \$\endgroup\$
    – Fast Snail
    Commented Mar 31, 2015 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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