Part Number: MSP430F5529
Tool/software: Code Composer Studio
I am working on a problem where I have to do multiplication, and then place the results into an array. I am doing this with nested subroutines. I am calling my subroutine incorrectly somehow, I believe. I am also unsure how to dump my product value back into the current array address. If I could get some help on this, I would greatly appreciate it. Thank you for your time in advance.
.cdecls C,LIST,"msp430.h" ;Include device header file
.def RESET ;Export program entry-point to
;make it known to linker.
.def calc_power
.def SW_Mult
.def HW_Mult
.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.
.data
b: .int 2 ;Create variable and initialize it to 2
val: .int 2 ;Create variable for product placement init 0
RESET: mov.w #__STACK_END,SP ;Initialize stack pointer
mov.w #WDTPW|WDTHOLD,&WDTCTL ;Stop watchdog timer
;-------------------------------------------------------------------------------
; Main loop
;-------------------------------------------------------------------------------
main: mov.w #hwarr, R7 ;starting address of hwarr to R7
mov.w #swarr, R8 ;starting address of swarr to R8
clr.w R9
hwnext: mov.w @R7+, R9 ;get next hwarr element
cmp #0, R9 ;is it a null?
jeq swnext ;if yes, go to swnext
call calc_power ;calculate powers of 2
swnext: mov.w @R8+, R9 ;get next swarr element
cmp #0, R9 ;is it a null?
jeq lend ;if yes, go to end
calc_power:
call HW_Mult
mov.w #val, R9
HW_Mult:
mov.w b, &MPY ;move b to R5
mov.w val, &OP2 ;move val to R6
nop ;3 clock cycles
nop
nop
mov RESLO, &val ;put product in val variable
ret
SW_Mult:
hwarr: .int 2, 2, 2, 2, 2 ;hw mult array
swarr: .int 2, 2, 2, 2, 2 ;sw mult array
lend: nop
;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
.end
