Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 21936

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

$
0
0

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.


Viewing all articles
Browse latest Browse all 21936

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>