如何解决MSP430的汇编中正确的函数调用和数组操作
我正在制作一个程序,该程序将乘以2的乘方并将乘积放入数组的元素中。我想使用硬件乘法器(并将这些乘积放入一个阵列)和软件乘法器(并将这些乘积放入自己的阵列)来执行此操作。如果可能的话,我也想使用嵌套子程序来做到这一点。我已经到达需要开始调用子例程的地步,但是我陷入了困境。当我拨打第一个电话时,我得到了垃圾。我确信我不熟悉此IDE(Code Composer Studio)和处理器(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 ;hw mult array
swarr: .int 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。