Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TTL Lab 5 Exercise 3 Calculate Average
- ;***************************************************************
- ;This file provides some pre-defined assembly instructions that
- ;students can add to in order to perform an averaging tasks.
- ; //By A. Mason, Aug 2017//
- ;***************************************************************
- ;Assembler directives
- THUMB
- ;***************************************************************
- ;EQUates
- ;Vectors
- VECTOR_TABLE_SIZE EQU 0x000000C0 ;KL25Z
- VECTOR_SIZE EQU 4 ;Bytes per vector
- ;Memory
- SSTACK_SIZE EQU 0x00000100
- ;NVIC
- ICER EQU 0xE000E180
- ;**********************************************************************
- ;Vector Table Mapped to Address 0 at Reset
- ;Linker requires __Vectors to be exported
- AREA RESET, DATA, READONLY
- EXPORT __Vectors
- __Vectors
- DCD SP_INIT ;stack pointer value when stack is empty
- DCD Reset_Handler ;reset vector
- SPACE (VECTOR_TABLE_SIZE - (2 * VECTOR_SIZE))
- ALIGN
- ;**********************************************************************
- AREA RAM,DATA,READWRITE
- ;Allocate system stack
- SSTACK SPACE SSTACK_SIZE
- SP_INIT
- ;Variables go here
- RAM_Data SPACE 64 ;reserve space for 64 variables @ label Ram_Data
- ;**********************************************************************
- ;Program
- ;Linker requires Reset_Handler
- AREA StudentCode,CODE,READONLY
- ENTRY
- EXPORT Reset_Handler
- Reset_Handler
- CPSID I ;Mask interrupts
- ; DISABLE INTERRUPTS
- LDR R0, =ICER ;R0 = &ICER
- MOVS R1, #0 ; R1 = 0
- MVNS R1, R1 ; R1 = 0xFFFFFFFF
- STR R1, [R0, #0]; ICER = 0xFFFFFFFF
- ; INIT STACK POINTER
- LDR R0, =SP_INIT ; load base address
- MOV SP, R0 ; set SP to base address
- ;**********************************************************************
- ;*Top of User Code*****************************************************
- ;**********************************************************************
- Main
- ; Load constants
- LDR R6, =ROM_Con
- LDR R7, =RAM_Data
- ; add student code below
- LDR R3, =0x00000000 ; I forgot
- LDR R4, =0x00000000 ; Running total
- LDR R5, =0x00000000 ; Counter variable
- looptime
- LDRB R2,[R6]
- ADDS R6, R6, #1 ; Increments address
- ADDS R5, R5, #1 ; Increments counter
- ADDS R4, R4, R2 ; Add the currently loaded value to the sum register
- CMP R5, #8
- BNE looptime
- LSRS R4, R4, #3
- STR R4, [R7]
- ; Leave the next two lines at the end of all Main code
- B .
- ALIGN
- ;**********************************************************************
- ;ROM Constants go below
- ;**********************************************************************
- ROM_Con ;address label for constants stored in ROM
- DCB 1, 6, 2, 9 ;will store each decimal value as a hex byte
- DCB 7, 0, 3, 4
- ALIGN ; NEEDED AFTER CONSTANTS ARE DECLARED
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement