Advertisement
Guest User

331 shit

a guest
Oct 14th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. TTL Lab 5 Exercise 3 Calculate Average
  2. ;***************************************************************
  3. ;This file provides some pre-defined assembly instructions that
  4. ;students can add to in order to perform an averaging tasks.
  5. ; //By A. Mason, Aug 2017//
  6. ;***************************************************************
  7. ;Assembler directives
  8. THUMB
  9. ;***************************************************************
  10. ;EQUates
  11. ;Vectors
  12. VECTOR_TABLE_SIZE EQU 0x000000C0 ;KL25Z
  13. VECTOR_SIZE EQU 4 ;Bytes per vector
  14. ;Memory
  15. SSTACK_SIZE EQU 0x00000100
  16. ;NVIC
  17. ICER EQU 0xE000E180
  18. ;**********************************************************************
  19. ;Vector Table Mapped to Address 0 at Reset
  20. ;Linker requires __Vectors to be exported
  21. AREA RESET, DATA, READONLY
  22. EXPORT __Vectors
  23. __Vectors
  24. DCD SP_INIT ;stack pointer value when stack is empty
  25. DCD Reset_Handler ;reset vector
  26. SPACE (VECTOR_TABLE_SIZE - (2 * VECTOR_SIZE))
  27. ALIGN
  28. ;**********************************************************************
  29. AREA RAM,DATA,READWRITE
  30. ;Allocate system stack
  31. SSTACK SPACE SSTACK_SIZE
  32. SP_INIT
  33. ;Variables go here
  34. RAM_Data SPACE 64 ;reserve space for 64 variables @ label Ram_Data
  35.  
  36. ;**********************************************************************
  37. ;Program
  38. ;Linker requires Reset_Handler
  39. AREA StudentCode,CODE,READONLY
  40. ENTRY
  41. EXPORT Reset_Handler
  42.  
  43. Reset_Handler
  44. CPSID I ;Mask interrupts
  45. ; DISABLE INTERRUPTS
  46. LDR R0, =ICER ;R0 = &ICER
  47. MOVS R1, #0 ; R1 = 0
  48. MVNS R1, R1 ; R1 = 0xFFFFFFFF
  49. STR R1, [R0, #0]; ICER = 0xFFFFFFFF
  50. ; INIT STACK POINTER
  51. LDR R0, =SP_INIT ; load base address
  52. MOV SP, R0 ; set SP to base address
  53.  
  54. ;**********************************************************************
  55. ;*Top of User Code*****************************************************
  56. ;**********************************************************************
  57. Main
  58. ; Load constants
  59. LDR R6, =ROM_Con
  60. LDR R7, =RAM_Data
  61.  
  62. ; add student code below
  63. LDR R3, =0x00000000 ; I forgot
  64. LDR R4, =0x00000000 ; Running total
  65. LDR R5, =0x00000000 ; Counter variable
  66.  
  67. looptime
  68. LDRB R2,[R6]
  69. ADDS R6, R6, #1 ; Increments address
  70. ADDS R5, R5, #1 ; Increments counter
  71. ADDS R4, R4, R2 ; Add the currently loaded value to the sum register
  72. CMP R5, #8
  73. BNE looptime
  74. LSRS R4, R4, #3
  75. STR R4, [R7]
  76. ; Leave the next two lines at the end of all Main code
  77. B .
  78. ALIGN
  79.  
  80. ;**********************************************************************
  81. ;ROM Constants go below
  82. ;**********************************************************************
  83. ROM_Con ;address label for constants stored in ROM
  84. DCB 1, 6, 2, 9 ;will store each decimal value as a hex byte
  85. DCB 7, 0, 3, 4
  86. ALIGN ; NEEDED AFTER CONSTANTS ARE DECLARED
  87. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement