首页 > 解决方案 > MSP430 程序集中的正确函数调用和数组操作

问题描述

我正在制作一个程序,该程序将乘以 2 并将产品放入数组的元素中。我想使用 HW 乘法器(并将这些产品放入一个数组)和 SW 乘法器(并将这些产品放入它们自己的数组中)来做到这一点。如果可能的话,我也想使用嵌套的子例程来做到这一点。我已经到了需要开始调用子例程的地步,但我被卡住了。当我第一次打电话时,我得到了垃圾。我确信我只是没有正确调用,因为我不熟悉这个 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, 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

标签: assemblymsp430

解决方案


推荐阅读