assembly - 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
解决方案
推荐阅读
- python - 有没有办法让一个 URL 不变的网站变成 Web 浏览器?
- selenium - 在 Selenium 中设置用户代理
- javascript - 获取动态添加的输入值
- reactjs - 在 react-bootstrap-table2-toolkit 搜索栏中有字体真棒搜索图标
- pandas - 对 DataFrame 中的所有组合进行相同的计算
- terraform - 从用户到 SSH 密钥的映射创建 aws_transfer_ssh_key
- c - 有没有办法让我在 DevC++ 的 C 程序中更改特定文本的颜色?
- ionic-framework - 打开的应用程序仍然是桌面 Chrome 响应,它不是移动响应视图
- regex - 如果有多个,则匹配所有逗号
- laravel - Laravel 8 validate unique through columns and rows on create and update