Assembly Language help (Beginner)

Discussion in 'Embedded Systems and Microcontrollers' started by jean28, Jan 26, 2013.

  1. jean28

    Thread Starter Member

    Sep 5, 2012
    76
    0
    Hey guys. I am taking a Microprocessors course and I have a few labs that I have to do with my microcontrollers.

    I am using the TI MSP430 and the IAR Embedded Workbench IDE for programming it. The manual that I am using says that I should save the code as .asm file, but for some reason whenever I try to do it, it doesn't work exactly as it should and when I run the program I get an error.

    Could anyone give me an idea of what I am doing wrong?

    Here is the code:

    Code ( (Unknown Language)):
    1. #include       msp430.h
    2. ;--------------------------------------------------------------------------
    3.             ORG      0f800h    ; Program Start
    4. ;--------------------------------------------------------------------------
    5. RESET       mov      #0280h,SP                   ;  Initialize stackpointer
    6. StopWDT     mov      #WDTPW+WDTHOLD,&WDTCTL      ;   StopWDT
    7. SetupP1     bis.b    #1,&P1DIR                   ; P1.0 as output
    8. Main        xor.b    #1,&P1OUT                   ; Toggle P1.0
    9. Wait        mov      #50000,R15                  ; Delay to R15
    10. L1          dec      R15                         ; Decrement R15
    11.         jnz      L1                          ; Delay over?
    12.         jmp      Main                        ; Again?
    13. ;--------------------------------------------------------------------------
    14. ;       Interrupt Vectors
    15. ;--------------------------------------------------------------------------
    16.             ORG      0FFFEh                      ; MSP430 RESET Vector
    17.         DW       RESET                       ;
    18.         END

    Here is the error I get:

     
  2. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    Not sure that should be there..... Header files are usually for C compilers.... I'm not familiar with this chip, so I may be wrong...
     
  3. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Have you tried #include "file.h" ?
     
  4. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Not sure about IAR but CCS (Code Composer Studio) uses the same header files for both C and assembly language programs.

    Here's the front end from a CCS assembly language program for an MSP430G2231 which was gleaned from the TI example programs for the '2231 and CCS. Aren't there examples from TI for your processor and IAR?


    Regards, Mike

    Code ( (Unknown Language)):
    1. *******************************************************************************
    2. *******************************************************************************
    3.  
    4.         .cdecls C,LIST, "msp430g2231.h"
    5.  
    6.         .bss    count, 1
    7.         .bss    flags, 1
    8.  
    9. ;------------------------------------------------------------------------------
    10.         .text                           ; Progam Start
    11.         .global _main
    12. ;------------------------------------------------------------------------------
    13. TxPin   .equ    2
    14.  
    15. _main
    16.         mov.w   #0280h,SP               ; Init stackpointer (top of RAM)
    17.         mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT
    18.  
    19.         clr.b   &DCOCTL                 ; DCO calibrated 1-MHz settings
    20.         mov.b   &CALBC1_1MHZ,&BCSCTL1   ;
    21.         mov.b   &CALDCO_1MHZ,&DCOCTL    ;
    22.  
    23.         mov.b   #BIT6+BIT1+BIT0,&P1DIR  ; P1.6 & P1.0 outputs
    24.         mov.b   #BIT0,&P1OUT            ;
    25.  
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    I can provide an answer later when I find the time.
     
  6. jean28

    Thread Starter Member

    Sep 5, 2012
    76
    0
    I would really appreciate your help. Thank you very much.
     
  7. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    Ok, for starters, your first line should be

    #include "msp430.h"

    see post #3.
     
  8. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    Start from scratch.

    Open IAR Embedded Workbench.

    Select menu Project->Create New Project...
    Select double click on "asm", select "asm", click OK.
    Enter name of Project File.

    Select menu Project->Options...->Target Device-> select your mcu chip
    Select from same dialog Debugger-> Setup Driver->FET Debugger OK

    You should see an asm template called "asm.s43" in the editor window.
    Use this template as your starting point.
     
  9. jean28

    Thread Starter Member

    Sep 5, 2012
    76
    0
    Do I write my code over the code in asm.s43? My manual gives those exact same steps but it tells me to close asm.s43 and to create a new file.
     
  10. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    You can do either. We know that the template supplied by IAR works.
    Rather than throwing it out completely, compare both files and see what is common.

    Understand what each statement does. If you don't know, don't be afraid to ask.
    Find out what is essential and what isn't.
     
  11. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    Here is your code:

    Code ( (Unknown Language)):
    1.  
    2. #include       msp430.h
    3. ;--------------------------------------------------------------------------
    4.             ORG      0f800h    ; Program Start
    5. ;--------------------------------------------------------------------------
    6. RESET       mov      #0280h,SP                   ;  Initialize stackpointer
    7. StopWDT     mov      #WDTPW+WDTHOLD,&WDTCTL      ;   StopWDT
    8. SetupP1     bis.b    #1,&P1DIR                   ; P1.0 as output
    9. Main        xor.b    #1,&P1OUT                   ; Toggle P1.0
    10. Wait        mov      #50000,R15                  ; Delay to R15
    11. L1          dec      R15                         ; Decrement R15
    12.         jnz      L1                          ; Delay over?
    13.         jmp      Main                        ; Again?
    14. ;--------------------------------------------------------------------------
    15. ;        Interrupt Vectors
    16. ;--------------------------------------------------------------------------
    17.             ORG      0FFFEh                      ; MSP430 RESET Vector
    18.         DW       RESET                       ;
    19.         END
    20.  
    21.  
    Here is the IAR code:

    Code ( (Unknown Language)):
    1.  
    2.  
    3.    
    4.     #include "msp430.h"              ; #define controlled include file
    5.  
    6.         NAME    main                    ; module name
    7.  
    8.         PUBLIC  main                    ; make the main label vissible
    9.                                         ; outside this module
    10.         ORG     0FFFEh
    11.         DC16    init                    ; set reset vector to 'init' label
    12.  
    13.         RSEG    CSTACK                  ; pre-declaration of segment
    14.         RSEG    CODE                    ; place program in 'CODE' segment
    15.  
    16. init:   MOV     #SFE(CSTACK), SP        ; set up stack
    17.  
    18. main:   NOP                             ; main program
    19.         MOV.W   #WDTPW+WDTHOLD,&WDTCTL  ; Stop watchdog timer
    20.         JMP $                           ; jump to current location '$'
    21.                                         ; (endless loop)
    22.         END
    23.  
     
Loading...