I am making a program that is going to multiply powers of 2 and place the products into the elements of an array. I want to do this using the HW multiplier (and placing those products into an array) and the SW multiplier (and placing those products into their own array). I also want to do this using nested subroutines if possible. I have gotten to the point that I need to start calling the subroutines, but I am getting stuck. I get garbage when I make the first call. I am sure I am just not calling properly as I am unfamiliar with this IDE (Code Composer Studio) and the processor (MSP430F5529).
.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
hval: .int 2 ;Create variable for product placement init 0
sval: .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 hcalc_power ;calculate powers of 2
jmp hwnext
swnext: mov.w @R8+, R9 ;get next swarr element
cmp #0, R9 ;is it a null?
jeq lend ;if yes, go to end
call scalc_power
hcalc_power:
call HW_Mult
mov.w #hval, R9
RET
scalc_power:
call SW_Mult
mov.w #sval, R10
RET
HW_Mult:
mov.w b, &MPY ;move b to R5
mov.w hval, &OP2 ;move val to R6
nop ;3 clock cycles
nop
nop
mov RESLO, &hval ;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