Tool/software: Code Composer Studio
I have a piece of code that I am working on (that you guys have already helped me immensely with) that calculates the powers of 2 and places them into two separate arrays (one array for HW multiplication and one array for SW multiplication). I have all of the array logic in place and functional as well as the HW multiplier function. I have some vague documentation on how to implement the Shift-and-Add algorithm, but it doesn't actually include anything for basic integer-integer multiplication. It also doesn't include any code examples at all. If you guys have any input on how I can write a block to perform this operation, I would greatly appreciate it. I will include my code here for anyone who wishes to look at it.
.cdecls C,LIST,"msp430.h" ;Include device header file
.def RESET ;Export program entry-point to
;make it known to linker.
.def hcalc_power
.def scalc_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 1 ;Create variable for product placement init 0
sval: .int 1 ;Create variable for product placement init 0
hwarr: .int 2, 2, 2, 2, 2 ;hw mult array
swarr: .int 1, 1, 1, 1, 1 ;sw mult array
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.b @R7+, R9 ;get next hwarr element
cmp #2, R9 ;is it a 2?
jne swnext ;if not, go to swnext
call #hcalc_power;calculate powers of 2
mov.w hval, 0(R7) ;put product into current array element
inc.w R7 ;increment R7 or it won't fully move to next element
jmp hwnext
swnext: mov.w @R8+, R9 ;get next swarr element
cmp #1, R9 ;is it a 1?
jne lend ;if not, go to end
call #scalc_power;calculate powers of 2 again
jmp swnext
hcalc_power:
mov.w b, R5 ;pass b to register for HW_Mult subroutine
mov.w hval, R6 ;ditto for hval
call #HW_Mult
ret
scalc_power:
mov.w b, R5 ;pass b to register for HW_Mult subroutine
mov.w sval, R6 ;ditto for hval
call #SW_Mult
ret
HW_Mult:
mov.w R5, &MPY ;get R5
mov.w R6, &OP2 ;get R6
nop ;3 clock cycles
nop
nop
mov RESLO, &hval;multiply and put product in hval
ret
SW_Mult:
ret
lend: nop
;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
.end