Skip to content

Instantly share code, notes, and snippets.

@chrisdel101
Last active March 27, 2021 02:41
Show Gist options
  • Save chrisdel101/4ec4320d60690b9d9d63107a1f704b55 to your computer and use it in GitHub Desktop.
Save chrisdel101/4ec4320d60690b9d9d63107a1f704b55 to your computer and use it in GitHub Desktop.
;The semicolon is used to lead an inline documentation
;When you write your program, you could have your info at the top document lock
;For Example: Your Name, Student Number, what the program is for, and what it does etc.
;;; Directives
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
; Linker requires __Vectors to be exported
AREA RESET, DATA, READONLY
EXPORT __Vectors
__Vectors
DCD 0x20001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector
ALIGN
;Your Data section
;AREA DATA
SUM DCD 0
SUMP DCD SUM
N DCD 7
NUM1 DCD 3, -7, 2, -2, 10, 20, 30
POINTER DCD NUM1
; The program
; Linker requires Reset_Handler
AREA MYCODE, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
;;;;;;;;;;User Code Start from the next line;;;;;;;;;;;;
LDR R1, N ; load size of array -
; a counter for how many elements are left to process
LDR R2, POINTER ; load base pointer of array
MOV R0, #0 ; initialize accumulator
;3, -7, 2, -2, 10, 20, 30
LOOP
LDR R3, [R2], #4 ; load value from array, AUTO-INDEX
; increment array pointer to next word
CMP R3, #5 ; compare curent val with 5
BGT over5 ; if current is greater than 5 branch
GOTO
;ADD R0, R0, R3 ; add value from array to accumulator
SUBS R1, R1, #1 ; decrement work counter
BGT LOOP ; keep looping until counter is zero
LDR R4, SUMP ; WORKS - I can see address of SUMP in R4
STR R0, [R4] ; CAN't TELL - no reaction so don't know. PC does change tho.
LDR R6, [R4] ; DOESN'WORK - nothing in R6. Don't know why.
B STOP
;sub-routine
over5
ADD R0, R0, R3 ; add curent val to sum
B GOTO
STOP
B STOP
END
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment