Advertisement
Guest User

MSP430 Average

a guest
Sep 15th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. ;-------------------------------------------------------------------------------
  2. ; MSP430 Assembler Code Template for use with TI Code Composer Studio
  3. ;
  4. ;
  5. ;-------------------------------------------------------------------------------
  6. .cdecls C,LIST,"msp430.h" ; Include device header file
  7.  
  8. ;-------------------------------------------------------------------------------
  9. .def RESET ; Export program entry-point to
  10. ; make it known to linker.
  11. ;-------------------------------------------------------------------------------
  12. .text ; Assemble into program memory.
  13. .retain ; Override ELF conditional linking
  14. ; and retain current section.
  15. .retainrefs ; And retain any sections that have
  16. ; references to current section.
  17.  
  18. ;array .word 2,3,4,5,6,4,4,5
  19. array .word 5,5,5,6,9,4,7,3
  20. size .word 9 ;; maybe this has to be 8?
  21.  
  22. ;-------------------------------------------------------------------------------
  23. RESET mov.w #__STACK_END,SP ; Initialize stackpointer
  24. StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
  25.  
  26.  
  27. ;-------------------------------------------------------------------------------
  28. ; Main loop here
  29. ;-------------------------------------------------------------------------------
  30.  
  31. mov #array, r4
  32. mov size, r5
  33. mov #0, r6 ;; this is the sum result
  34. mov #0, r7 ;; this is the index
  35. mov #0, r8 ;; this is the result of the division
  36.  
  37. sumLoop:
  38. dec r5
  39. jz division
  40. add array(r7), r6
  41. incd r7
  42. jmp sumLoop
  43.  
  44. division:
  45. sub #8, r6
  46. jl done
  47. inc r8
  48. jmp division
  49.  
  50. done:
  51. jmp $
  52. nop
  53.  
  54.  
  55.  
  56.  
  57.  
  58. ;-------------------------------------------------------------------------------
  59. ; Stack Pointer definition
  60. ;-------------------------------------------------------------------------------
  61. .global __STACK_END
  62. .sect .stack
  63.  
  64. ;-------------------------------------------------------------------------------
  65. ; Interrupt Vectors
  66. ;-------------------------------------------------------------------------------
  67. .sect ".reset" ; MSP430 RESET Vector
  68. .short RESET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement