• AVR Freaks

n00b MPASM error - weird?

Author
stormBytes
Starting Member
  • Total Posts : 64
  • Reward points : 0
  • Joined: 2010/01/27 07:15:02
  • Location: 0
  • Status: offline
2010/01/29 07:46:17 (permalink)
0

n00b MPASM error - weird?

Hey Folks,

Working on a book-lead tutorial and I'm getting a really weird error! I've gone through my code a dozen times and I can't catch it.

Help!





; PROGRAM FUNCTION
; =============================================================================

list p=16F54 ; list directive to define processor
#include <p16F5x.inc> ; processor specific variable definitions

; CONFIG BITS (Unused)
; =============================================================================

; __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC

; DECLARATIONS
; =============================================================================

ORG 1FFh
goto Start
ORG 0

; SUBROUTINES
; =============================================================================

Init clrf PORTA ; reset PORTA
clrf PORTB ; reset PORTB
movlw B'11111110'
tris PORTA
movlw B'11111111'
tris PORTB
retlw 0

; VARIABLE DEFINITIONS (Unused)
; =============================================================================

TEMP_VAR UDATA
temp RES 1 ; example variable definition

; PROGRAM START
; =============================================================================

Start
call Init ; Initiaize Program

Main
bsf PORTA,0
goto Main ; Loop Indefinitely

END ; EOF: PIC-16F54-SOURCE-01.asm






And here's what I'm getting out of MPASM:



Error[152] C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\DESKTOP\PROJECTS32\PIC-16F54-SOURCE-01.ASM 40 : Executable code and data must be defined in an appropriate section


I'm getting the error on all my labels for some odd reason.


-
Daniel
#1

17 Replies Related Threads

    ppater
    Super Member
    • Total Posts : 1002
    • Reward points : 0
    • Joined: 2006/08/26 10:33:06
    • Location: Ivry, France
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 08:27:09 (permalink)
    0
    You may be assembling in relocatable mode and your code is absolute...

    Best regards,
    Philippe.

    Pic Micro Pascal for All!
    #2
    stormBytes
    Starting Member
    • Total Posts : 64
    • Reward points : 0
    • Joined: 2010/01/27 07:15:02
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 08:29:53 (permalink)
    0
    How would I know? Where would I change that?

    -
    Daniel
    #3
    stormBytes
    Starting Member
    • Total Posts : 64
    • Reward points : 0
    • Joined: 2010/01/27 07:15:02
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 08:37:11 (permalink)
    0
    I tried going into Build Options and changing relocatable/absolute. Same problem. Actually when I set it to Absolute I get another (additional) error.

    -
    Daniel
    #4
    nur53
    Super Member
    • Total Posts : 1102
    • Reward points : 0
    • Joined: 2008/06/07 08:16:33
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 08:39:27 (permalink)
    2 (1)

    Try this :


    list p=16F54 ; list directive to define processor
    #include <p16F54.inc> ; processor specific variable definitions

    ; CONFIG BITS (Used)
    ; =============================================================================

    ; __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC


    ; =============================================================================

    ORG 0x0000
    goto Start


    ; SUBROUTINES
    ; =============================================================================

    Init clrf PORTA ; reset PORTA
    clrf PORTB ; reset PORTB
    movlw B'11111110'
    tris PORTA
    movlw B'11111111'
    tris PORTB
    retlw 0


    ; PROGRAM START
    ; =============================================================================

    Start
    call Init ; Initiaize Program

    Main
    bsf PORTA,0
    goto Main ; Loop Indefinitely

    END ; EOF: PIC-16F54-SOURCE-01.asm





    #5
    stormBytes
    Starting Member
    • Total Posts : 64
    • Reward points : 0
    • Joined: 2010/01/27 07:15:02
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 09:02:33 (permalink)
    0

    ORIGINAL: nur53

    Try this :


    list p=16F54 ; list directive to define processor
    #include <p16F54.inc> ; processor specific variable definitions

    ; CONFIG BITS (Used)
    ; =============================================================================

    ; __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC


    ; =============================================================================

    ORG 0x0000
    goto Start


    ; SUBROUTINES
    ; =============================================================================

    Init clrf PORTA ; reset PORTA
    clrf PORTB ; reset PORTB
    movlw B'11111110'
    tris PORTA
    movlw B'11111111'
    tris PORTB
    retlw 0


    ; PROGRAM START
    ; =============================================================================

    Start
    call Init ; Initiaize Program

    Main
    bsf PORTA,0
    goto Main ; Loop Indefinitely

    END ; EOF: PIC-16F54-SOURCE-01.asm








    Other then the #include statement, the ORG statements (1 re-written, 1 omitted). What's changed in your code?

    I tried it (with the observed changes) without any difference.

    -
    Daniel
    #6
    stormBytes
    Starting Member
    • Total Posts : 64
    • Reward points : 0
    • Joined: 2010/01/27 07:15:02
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 09:30:27 (permalink)
    0
    Here's the contents of m LIST file from MPASM.



    MPASM 5.35beta PIC-16F54-SOURCE-01.ASM 1-29-2010 11:00:47 PAGE 1


    LOC OBJECT CODE LINE SOURCE TEXT
    VALUE

    00001
    00002 ; PROGRAM FUNCTION
    00003 ; =============================================================================
    00004
    00005 LIST P=16F54 ; list directive to define processor
    00006 #INCLUDE <P16F5X.INC> ; processor specific variable definitions
    00001 LIST
    00002 ; P16F5X.INC Standard Header File, Version 4.00 Microchip Technology, Inc.
    00128 LIST
    00007
    00008 ; CONFIG BITS (Unused)
    00009 ; =============================================================================
    00010
    00011 ; __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC
    00012
    00013 ; DECLARATIONS
    00014 ; =============================================================================
    00015
    00016 ORG 1FFH
    01FF 0A?? 00017 GOTO START
    00018 ORG 0
    00019
    00020 ; SUBROUTINES
    00021 ; =============================================================================
    00022
    0000 0065 00023 INIT CLRF PORTA ; reset PORTA
    0001 0066 00024 CLRF PORTB ; reset PORTB
    0002 0CFE 00025 MOVLW B'11111110'
    0003 0005 00026 TRIS PORTA
    0004 0CFF 00027 MOVLW B'11111111'
    0005 0006 00028 TRIS PORTB
    0006 0800 00029 RETLW 0
    00030
    00031 ; VARIABLE DEFINITIONS (Unused)
    00032 ; =============================================================================
    00033
    00034 TEMP_VAR UDATA
    0000 00035 TEMP RES 1 ; example variable definition
    00036
    00037 ; PROGRAM START
    00038 ; =============================================================================
    00039
    Error[152] : Executable code and data must be defined in an appropriate section
    0001 00040 START CALL INIT ; Initiaize Program
    00041
    Error[152] : Executable code and data must be defined in an appropriate section
    0001 00042 MAIN BSF PORTA,0
    Error[152] : Executable code and data must be defined in an appropriate section
    0001 00043 GOTO MAIN ; Loop Indefinitely
    00044
    00045 END ; EOF: PIC-16F54-SOURCE-01.asm
    MPASM 5.35beta PIC-16F54-SOURCE-01.ASM 1-29-2010 11:00:47 PAGE 2


    SYMBOL TABLE
    LABEL VALUE

    C 00000000
    DC 00000001
    F 00000001
    FSR 00000004
    INDF 00000000
    INIT 00000000
    MAIN 00000001
    NOT_PD 00000003
    NOT_TO 00000004
    PA0 00000005
    PA1 00000006
    PA2 00000007
    PCL 00000002
    PORTA 00000005
    PORTB 00000006
    PS0 00000000
    PS1 00000001
    PS2 00000002
    PSA 00000003
    START 00000001
    STATUS 00000003
    T0CS 00000005
    T0SE 00000004
    TEMP 00000000
    TMR0 00000001
    W 00000000
    Z 00000002
    _CP_OFF 00000FFF
    _CP_ON 00000FF7
    _HS_OSC 00000FFE
    _LP_OSC 00000FFC
    _RC_OSC 00000FFF
    _WDT_OFF 00000FFB
    _WDT_ON 00000FFF
    _XT_OSC 00000FFD
    __16F54 00000001
    __DEBUG 1

    Errors : 3
    Warnings : 0 reported, 0 suppressed
    Messages : 0 reported, 0 suppressed





    -
    Daniel
    #7
    stormBytes
    Starting Member
    • Total Posts : 64
    • Reward points : 0
    • Joined: 2010/01/27 07:15:02
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 10:13:48 (permalink)
    0
    Okay this is going to sound funny but after some trial and error, I realized that the offending statements were the variables declared, omitted in your revision. I hadn't noticed this initially (too much staring at a computer screen I guess, or maybe age?).

    Regardless, thanks!

    Could you enlighten me as to why exactly those statements 'offended' MPASM?

    ORIGINAL: nur53

    Try this :


    list p=16F54 ; list directive to define processor
    #include <p16F54.inc> ; processor specific variable definitions

    ; CONFIG BITS (Used)
    ; =============================================================================

    ; __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC


    ; =============================================================================

    ORG 0x0000
    goto Start


    ; SUBROUTINES
    ; =============================================================================

    Init clrf PORTA ; reset PORTA
    clrf PORTB ; reset PORTB
    movlw B'11111110'
    tris PORTA
    movlw B'11111111'
    tris PORTB
    retlw 0


    ; PROGRAM START
    ; =============================================================================

    Start
    call Init ; Initiaize Program

    Main
    bsf PORTA,0
    goto Main ; Loop Indefinitely

    END ; EOF: PIC-16F54-SOURCE-01.asm







    -
    Daniel
    #8
    400_up
    Super Member
    • Total Posts : 776
    • Reward points : 0
    • Joined: 2004/04/21 09:19:15
    • Location: Texas,USA
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 10:29:53 (permalink)
    5 (1)
    The linker is invoked by using linker directives such as "udata". When you originally built this code (your first post) you were mixing absolute and relocatable directives. The ORG 1ffh in your original code is an absolute directive, the "TEMP_VAR udata" is a linker directive. After the udata you must use a code directive to tell the linker to start allocating ROM.
     
    TEMP_VAR udata
     
    mybyte res 2
     
     
    code
     
    Start
     
        etc, etc
     
    IMHO it is bad practice to mix absolute and linker directives, you invoked the linker without knowing it, and I think your project continues to invoke the linker, and again IMHO, the RAM and ROM sections should not be mixed. Take a look at the 16F54TMPO.asm file in the \Template\Object folder of your Microchip folder.
     
    I put directives basically in this order:
     
    ;what ever defines I need I/O etc
    #define myOut  PORTA,0
     
    ;maybe some constants
         contstant myConstant = 0x25
     
    ;RAM
    .sectionName (optional) udata (optional RAM address)
     
    myRam1 res 1
    myRam2 res 2
     
    ;interrupt ROM address
         code 0x1ff ;your device interrupt vector
     
    ;ISR goes her
         retfie
     
    ;start of program
     
         code 0x000
    Init:
    ;initialize the device
     
          return
     
    Start:
          call     Init
     
    Main:
    ;main loop here
         goto    Main
     
     
         END
     
    Something like that.

    Robert Cauthon
    #9
    nur53
    Super Member
    • Total Posts : 1102
    • Reward points : 0
    • Joined: 2008/06/07 08:16:33
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 11:52:34 (permalink)
    0
    From code template :

    list p=16F54 ; list directive to define processor
    #include <p16F5x.inc> ; processor specific variable definitions

    __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC

    ; '__CONFIG' directive is used to embed configuration word within .asm file.
    ; The lables following the directive are located in the respective .inc file.
    ; See respective data sheet for additional information on configuration word.
    ;**********************************************************************
    RESET_VECTOR CODE 0x1FF ; processor reset vector
    goto start

    MAIN CODE 0x000
    start
    nop ; example code
    call Init ; Initiaize Program

    Main
    bsf PORTA,0
    goto Main ; Loop Indefinitely

    ; remaining code goes here

    Init clrf PORTA ; reset PORTA
    clrf PORTB ; reset PORTB
    movlw B'11111110'
    tris PORTA
    movlw B'11111111'
    tris PORTB
    retlw 0

    END ; directive 'end of program'


    #10
    stormBytes
    Starting Member
    • Total Posts : 64
    • Reward points : 0
    • Joined: 2010/01/27 07:15:02
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 12:34:57 (permalink)
    0
    Hey Robert,

    Thanks for that info, though its a tad over my head at the moment. I don't know the first thing about linker files. I hope to get through these tutorials, write some code and hopefully do some more reading. I'm not entirely sure I want to get into the 'blood and guts' of MPASM. Seems awfully complex. I opted to start off with ASM and MPLab as I'd like to build a solid foundation (not to mention its free!). My goal is to migrate to wring C code as quickly as possible, but I'm not going to jump the gun on that. I've got a couple of ASM books I'm going to work through first.

    I'd love to hear any advice you have on how to best proceed. I'm not looking to code embedded systems for a living, this is more of a hobby. It is fun though, and the prospect of making my own 'gadgets' afterwards makes it all that much more worthwhile!

    -
    Daniel
    #11
    400_up
    Super Member
    • Total Posts : 776
    • Reward points : 0
    • Joined: 2004/04/21 09:19:15
    • Location: Texas,USA
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 13:06:38 (permalink)
    0
    Since you are just starting out, unless you have a compelling reason not to, go with the 18F devices.  Writing programs for them is a little easier because they have one ROM address space and the RAM pages easier to use than the 16F's, because of the ACCESS/BANKED bit in the opcodes. Microchip also has a C compiler to use with them (the student edition is free), and they generally have better peripherials. There is a wealth of code written for them (ASM and C), check out the application notes on the Microchip web site, so learning to use them will be fairly easy.
     
    When writing ASM don't program absolute code, use the linker. The linker is a preprocessor program that manages memory for you, if you need help learning this just ask on the forum. Members are glad to help you. There is a linker user's guide to get you started.
     
    Good luck!

    Robert Cauthon
    #12
    stormBytes
    Starting Member
    • Total Posts : 64
    • Reward points : 0
    • Joined: 2010/01/27 07:15:02
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 14:09:10 (permalink)
    0
    Thanks Robert. Actually I've already picked up a couple of PIC16x micros. I've got an F88 and an F12683. I've also got a couple of books, all of which deal with PIC16 series chips so... for the time being I'm gonna stick with that. Another thing is that the larger micros are a lot more intimidating. I'm still learning about configuration bits, SFR's, etc. The smaller/older PICs seem to be simpler. I've read about switching banks using the Status register, so far nothing overly daunting!

    I've seen Microchip's (free edition) C compiler. How does that fit into the workflow? Is it a replacement IDE or does it merely work (compile) through MPLab?

    I'll take to heart what you said about staying away from absolute code. For the time being, I'm going through the examples in my current book. I imagine it addresses this issue, albeit somewhat later down the line.

    This place is really terrific. Folks are helpful and the general atmosphere rocks!

    -
    Daniel
    #13
    Stefan Uhlemayr
    Super Member
    • Total Posts : 4292
    • Reward points : 0
    • Joined: 2005/05/12 12:25:46
    • Location: Germany
    • Status: offline
    RE: n00b MPASM error - weird? 2010/01/29 14:21:29 (permalink)
    0
    Hi Daniel,

    you may have a look to this nice tutorial from David, which could help you pretty much with your first steps on a PIC:
    ORIGINAL: Flying with SoftWare Favorites Gallery List

    -------------------------------------------------------------------
    [ Tutorials:                                                                              ]
    -------------------------------------------------------------------

    Gooligum Electronics PIC Tutorials (baseline- and midrange-PIC's, assembler and "C"): from David Meiklejohn

    Take the time and work yourself through this tutorial. Once you've done that, you might switch over to the PIC18-series, as they offer a lot of advantages to you (some of them Robert pointed out already wink). The only thing they miss up to now is a good assembler-tutorial ("C"-tutorials you may find in the sw-gallery), but most of the things you'll learn in David's tutorial you can "use" for the PIC18-series, too.

    Hope this helps,
    Stefan
    #14
    400_up
    Super Member
    • Total Posts : 776
    • Reward points : 0
    • Joined: 2004/04/21 09:19:15
    • Location: Texas,USA
    • Status: offline
    RE: n00b MPASM error - weird? 2010/02/01 07:39:53 (permalink)
    0

    Original: stormBytes
    I've seen Microchip's (free edition) C compiler. How does that fit into the workflow? Is it a replacement IDE or does it merely work (compile) through MPLab?

     
    It runs under the MPLAB IDE, or can be invoked from the command line, but it only comiles for the PIC18 family, not the PIC16. There are other Microchip C comilers for the more advanced families, the 16 and 32 bit devices, but not one for the PIC16's. There are third party C compilers available for the PIC16 family though, I think HiTech C or a similar name, I've never used one.
     
    On the up side, everything you learn in ASM for a PIC16 will be of benefit if you ever decide to go to the PIC18's. Of course you may decide that the PIC16's suite your needs and never use a PIC18, but you will have to go outside of Microchip to use a C compiler.

    Robert Cauthon
    #15
    stormBytes
    Starting Member
    • Total Posts : 64
    • Reward points : 0
    • Joined: 2010/01/27 07:15:02
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/02/01 09:25:31 (permalink)
    0

    ORIGINAL: Stefan Uhlemayr

    Hi Daniel,

    you may have a look to this nice tutorial from David, which could help you pretty much with your first steps on a PIC:
    ORIGINAL: Flying with SoftWare Favorites Gallery List

    -------------------------------------------------------------------
    [ Tutorials:                                                                              ]
    -------------------------------------------------------------------

    Gooligum Electronics PIC Tutorials (baseline- and midrange-PIC's, assembler and "C"): from David Meiklejohn

    Take the time and work yourself through this tutorial. Once you've done that, you might switch over to the PIC18-series, as they offer a lot of advantages to you (some of them Robert pointed out already wink). The only thing they miss up to now is a good assembler-tutorial ("C"-tutorials you may find in the sw-gallery), but most of the things you'll learn in David's tutorial you can "use" for the PIC18-series, too.

    Hope this helps,
    Stefan


    Stefan,

    That's the best advice I've gotten so far on my journey to learning embedded development. Gooligum tutorials a really terrific, though I find myself having to research some of the scantly covered topics to be able to follow along. (XOR for one!).

    I intend to go through all of the tutorials thoroughly.

    -
    Daniel
    #16
    stormBytes
    Starting Member
    • Total Posts : 64
    • Reward points : 0
    • Joined: 2010/01/27 07:15:02
    • Location: 0
    • Status: offline
    RE: n00b MPASM error - weird? 2010/02/01 09:30:42 (permalink)
    0

    ORIGINAL: 400_up

    It runs under the MPLAB IDE, or can be invoked from the command line, but it only comiles for the PIC18 family, not the PIC16. There are other Microchip C comilers for the more advanced families, the 16 and 32 bit devices, but not one for the PIC16's. There are third party C compilers available for the PIC16 family though, I think HiTech C or a similar name, I've never used one.

    On the up side, everything you learn in ASM for a PIC16 will be of benefit if you ever decide to go to the PIC18's. Of course you may decide that the PIC16's suite your needs and never use a PIC18, but you will have to go outside of Microchip to use a C compiler.


    Thanks for the info! Wow I didn't realize that C compilers were limited to the PIC18x series chips. I take it its a Microchip thing? I've recently purchased an EasyPIC6 dev board from mikroelectronika. Their C compiler, while I don't know how good it is, works for PIC12, PIC16, and PIC18 series chips. I'm just starting out and their free/trial version seems to be a solid bet. CCS's compilers are VERY expensive!

    Still, at this point I'm only starting to learn ASM, so I've also picked up an ICD2 clone to be able to do real time debugging of ASM code. Unfortunately mikroe's ICD doesn't work with ASM and only works with C if you're using their proprietary compiler.


    -
    Daniel
    #17
    Ian.M
    Super Member
    • Total Posts : 13225
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    RE: n00b MPASM error - weird? 2010/02/01 18:49:47 (permalink)
    0
    Before going for a third party compiler, one should note that although porting Microchip C example code is possible and not very difficult (if somewhat tedious) for anyone with a reasonable amount of C experiance, unfortunately the licence terms of some Microchip Libraries either prohibit their use with a non-Microchip tool chain or prohibit distribution of the ported version.

    Sourceboost have a free IDE which does work with Microchip ASM, HITECH PICC Lite and their own C, C++ and Basic.  It includes a reasonably good simulator but unfortunately cant talk to the Microchip Debuggers.  You can do full source debugging and also build BoostC (or their other languages) under MPLAB.  It supports midrange (mostly PIC16 and a few  PIC12) and PIC18 series parts.   Their free (unregistered) languages are limited to 2 banks ram and 2 Kword (midrange) or 4 Kbyte (PIC18) of compiled program and non-commercial use but DONT disable optimisation.  Their forum is active and helpful and the developers usually drop in if anyone has a real problem that isn't easily solved by RTFM.  The Full (non-commmercial) version of their C compiler is currently USD $69.95 and there is a Standard version currently at USD $29.95 which removes the RAM limits of the free version and relaxes the program size limit to double that of the free one. 

    I have debugged MPASM and C projects under their IDE and have purchased the FULL (non commercial) licence of their C compiler and a few other goodies like extra simulation plugins for their IDE and source to the libraries and their Novo RTOS.

    There are currently a few issues with MPASM assembler debug (simulator) support under their IDE V6.96 and also with newer versions of MPASM in recent MPLAB versions.  We all hope it will be sorted soon but for the moment its probably best to grab MPASMWIN V5.20 from [here], unzip it into the new sub-directory MPASM inside the Sourceboost IDE program directory and set the Sourceboost IDE assembler command line (select assembler as the toolsuite then you will find it in options) to: MPASM\MPASMWIN.EXE /aINHX8M /p%target% /rHEX /w2 /q which I am currently using successfully with the V6.95 IDE.  


    #18
    Jump to:
    © 2019 APG vNext Commercial Version 4.5