77 lines
2.8 KiB
NASM
77 lines
2.8 KiB
NASM
;-------------------------------------------------------------------------------
|
|
; MSP430 Assembler Code Template for use with TI Code Composer Studio
|
|
;
|
|
;
|
|
;-------------------------------------------------------------------------------
|
|
.cdecls C,LIST,"msp430.h" ; Include device header file
|
|
|
|
;-------------------------------------------------------------------------------
|
|
.def RESET ; Export program entry-point to
|
|
; make it known to linker.
|
|
.data
|
|
arr: .int "-25", "5", "22", "8", "-6", "14"
|
|
arrSize .int "6"
|
|
;-------------------------------------------------------------------------------
|
|
.text ; Assemble into program memory.
|
|
.retain ; Override ELF conditional linking
|
|
; and retain current section.
|
|
.retainrefs ; And retain any sections that have
|
|
; references to current section.
|
|
|
|
;-------------------------------------------------------------------------------
|
|
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
|
|
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
|
|
|
|
|
|
;-------------------------------------------------------------------------------
|
|
; Main loop here
|
|
;-------------------------------------------------------------------------------
|
|
main: push #arr ; Move the starting address of arr onto the stack
|
|
push #arraySize ; Push the arraySize onto the stack
|
|
call #SW_Mult
|
|
mov.w @SP, #6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SW_Mult: push R7 ; save r7, the sum
|
|
push R6 ; save R6, array size
|
|
push r4 ; save r4, pointer to array
|
|
mov.w 10(SP), R6 ; retreive array size
|
|
mov.w 12(SP, R7 ; retreive starting address
|
|
clr.w r8
|
|
clr.w r9
|
|
addIndex: mov.w @r4+, r5 ; increment byte counter
|
|
jmp comp
|
|
|
|
comp: cmp #0, r5
|
|
clr.w r8 ; clear result
|
|
jl ext
|
|
sum2 cmp #16, r10
|
|
jz step2
|
|
; sxt r5 ; sign-extend value
|
|
|
|
ext: sxt r5 ; sign-extend value
|
|
jmp sum2
|
|
step2: add
|
|
|
|
|
|
|
|
|
|
|
|
;-------------------------------------------------------------------------------
|
|
; Stack Pointer definition
|
|
;-------------------------------------------------------------------------------
|
|
.global __STACK_END
|
|
.sect .stack
|
|
|
|
|
|
;-------------------------------------------------------------------------------
|
|
; Interrupt Vectors
|
|
;-------------------------------------------------------------------------------
|
|
.sect ".reset" ; MSP430 RESET Vector
|
|
.short RESET
|
|
|