问题描述
我正在编写一个程序,该程序计算2的幂,并使用答案填充两个数组(一个数组使用硬件乘法器,第二个数组使用软件乘法)。在这种情况下,软件乘法需要使用Shift-and-Add算法。我迷失在如何在我的代码中实际实现这一点。如果有人可以提供帮助,我将永远感激不已。
.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 ;hw mult array
swarr: .int 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
mov.w b,R5 ;pass b to R5 for calc_power
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 -- takes 36 cc
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 ;loop
swnext: mov.b @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 -- takes
mov.w sval,0(R8) ;put product into current array element
inc.w R8 ;increment R8 or it won't fully move to next element
jmp swnext ;loop
hcalc_power:
mov.w hval,R6 ;pass hval to R6 for HW_Mult
call #HW_Mult
ret
scalc_power:
mov.w sval,R6 ;pass sval to R6 for SW_Mult
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
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)