This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

WEBENCH® Tools/MSP430G2153: Problems in compiling assembly code in IAR Workbench

Part Number: MSP430G2153

Tool/software: WEBENCH® Design Tools

First time here, i'm a new user and i'm trying to compile some assembly codes but it's not working.

I did a code in C/C++ that calculates the square root using just sum and subtraction, and i tried to convert it to assembly, here goes de code:

main:


          mov.w #36,R15 ;put the value i want to calculate the square root in R15
          call Square_Root ;call function square root
          jmp End

Square_Root:


          mov.w #0,R14 ;R14 is a counter 'n' and it's set to zero
          tst.w R15 ; if the R15 = 0, go to end_2
          jz End_2
                          ;;initial estimative


         mov.w R15,R12 ;  Here is part of a division algorithm, R12 is the numerator
         mov.w #2,R11 ; R11 is the denominator:  R12/R11
         call Division_1
         mov.w R13,R10 ; R13 is the result of the division, put it in R10

                 

While:                     ; the algorithm for calculating the square root is basically this: x(n+1) = (x(n) + S/x(n))/2, after n+1 iteractions, S is the number i want to calculate the square root, in this case 0x36d
       

                            cmp #16,R14 ;compare R14 with 0x16d. The intention here is make a counter that inc up to 16
                            jeq End_2 ; if R14 = 16 -> jump to end_1

                           mov.w R15,R12 ; Here goes the division algorithm again, just passing the parameters
                           mov.w R10,R11 ; 
                           call Division_1
                           mov.w R13, R9 ; R9 = R13(the result of division)
                           add.w R10,R9 ; R9 = R9 + R10
                           mov.w R9,R12 ; Numerator
                           mov.w #2,R11 ; Denominator
                           call Division_1 ;
                           inc.w R14 ; inc R14 in 1
                           mov.w R13,R10 ; R10 = R13 Result of the last division
                           jmp While

End_1:
                          mov.w R10, R15; Put the result of the square root in R15
End_2:
                         ret


Division_1:
                       mov.w #0,R13 ; takes the counter to zero
Division_2:

                       cmp #0,R12 ; Compare R12 with 0

                      jl End_Division ; if less than zero -> jump to the final of division

                      jeq End_Division ; -> if equal to zero -> jump to the final of division

                     sub.w R11,R12 ; R12 = R12 - R11 -> R12 numerator, R11 Denominator
                     inc.w R13 ; inc the counter 
                     jmp Division_2

End_Division:
                    ret
End:
jmp $ ;infinity loop

well, i don't know if the code is clear enough, my apologize for that.

the error the iar workbench is giving me is:

 User error: Illegal opcode found on address 0x430E
Unable to execute: driver error. After the error occurred, the program counter (PC) was <unknown>.

Thank you for the help.

  • Hi Jucelino,

    I am a bit concerned about the first error mentioning address 0x430E because looking at the datasheet for the MSP430G2153 device mentioned in the thread title, there is no memory are there so there should be no code there. Are you using the MSP430G2153 device, or a different MSP430? I think something in your project settings may be off.

    You mentioned that you wrote the code in C/C++ before - when you changed over to assembly, did you make sure to set up the project for assembly in IAR? That involves going to Project > Create New Project > and select asm to make an assembly-only project.

    Do you know if you set the project up for the appropriate MSP430 device? After creating the project, go to Project > Options and under General Options on the Target tab, make sure that Device is set to the device that you are using (MSP430G2153?)

    Hopefully one of these may lead us to the root cause of your issue.

    Regards,
    Katie
  • Hi Jucelino,

    Do you have any update? Is there more we can do to help, or were you able to resolve your issue?

    Regards,
    Katie

**Attention** This is a public forum