我编写这段代码,目的是当A,B是2个长度为8的数字数组时,返回= ∑A∙B。
当程序进入RET命令时,出现错误: “在地址0X0上发现非法操作码”。 我不知道为什么会这样。
#include <msp430xG46x.h> ;define controlled include file
ORG 1100h
Arr1 DW 2,0,4,2,6,5,1,1
Arr2 DW 3,0,8,5,2,9,3,7
Size DW 8 ; Arr length
var1 DS32 1
RSEG CODE ; ORG 0x3100 - place program in 'CODE' segment in to Flash memory
RSEG CSTACK
Main
MOV #Arr1,R5
MOV #Arr2,R6
MOV Size,R7
CLR R8
Loop
call #Func
DEC R7
JNZ Loop
L1 JMP L1
Func
MOV @R5,R10 ;Adding @R6, @R5 times to R8
CLR R4
ADD @R6,R4
L2
DEC R10
JZ Result
ADD @R6,R4
ADC R9
JMP L2
Result
MOV R4,var1
MOV #2,R11
MOV R9,var1(R11)
ADD var1,R8
INCD R5
INCD R6
RET
;-------------------------------------------------------------------------------
COMMON INTVEC ; Interrupt Vectors
;-------------------------------------------------------------------------------
ORG RESET_VECTOR ; POR, ext. Reset
DW Main
END
答案 0 :(得分:1)
1)SP寄存器未初始化,因此您要将内存推到0x0000,这取决于您的MCU。这也使通话和提示变得一团糟。
2)您的代码以堆栈段结尾,因为RSEG CSTACK在RSEG代码之后且在您的代码之前。
更改
RSEG CODE ; ORG 0x3100 - place program in 'CODE' segment in to Flash memory
RSEG CSTACK
Main
到
RSEG CSTACK
RSEG CODE ; ORG 0x3100 - place program in 'CODE' segment in to Flash memory
Main MOV #SFE(CSTACK), SP