您好。我正在尝试使用ARM汇编语言为我的Raspberry Pi创建一个程序,该程序将4x4矩阵和4x1向量相乘。我目前的问题是我得到分段错误,当我运行调试程序时,似乎错误发生在_vectoradress
。
从我从一些谷歌搜索中收集到的,分段错误的可能原因是我试图访问一个不存在的内存地址或者某种程度上程序试图访问它无法访问的某些内存。但是,我无法理解在我的情况下这是怎么回事。
如果有人可以告诉我导致分段错误的错误,那会很棒。
我的代码:
File1中:
.section .data
.align 2
.global _matrixadress
.global _vectoradress
_matrix:
.word 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,15
_vector:
.word 1,2,3,4
.section .text
_matrixadress:
ldr r1, matrixadress
bx lr
_vectoradress:
ldr r2, vectoradress
bx lr
vectoradress:
.word _vector
matrixadress:
.word _matrix
/ * e.o.f. * /
文件2
.section .data
.align 2
.global _start
.global Resultat
.global adressR
adressR:
.zero 256
.section .text
_start:
blal _matrixadress
mov r4, #0 /*initialises a counter in r4 with the value 0, this counter will be used to control Resultat */
mov r5, #0 /*initiates r5 with the value 0, to be used as a counter for the inner loop */
mov r6, #0 /* intitiated r6 with the value 0, to be used as a counter for the outer loop*/
mov r0, #0 /* initiates r0 with value 0, to be used for addition in the loop*/
ldr r4, Resultat
blal _vectoradress
loop: /*the start of the loop*/
mul r0,r2,r1 /*multiplies two elements of the matrix and the vectors*/
add r3,r0 /* adds the result from r0 into r3 */
mov r0, #0 /*restores 0 to r0 to be used in the next iteration*/
add r1, r1, #16 /*adds 16 to r1 to be able to get the next value of the matrix */
add r2, r2, #16 /*adds 16 to r2 to be able to get the next value of the vector */
add r5, r5, #1 /*adds 1 to r5, since it is time to add to the counter*/
cmp r5, #4 /*compares r5 to 4 for the loop control statement below */
bne loop /*if r4 and r5 was not equal, return to the loop for the next miltiplication */
mov r5, #0 /*resets teh counter in r5 */
add r6, r6, #1 /* add 1 to the counter, because it is time to count - hell yeah */
str r3, [r4] /* stores the value of r3 (the result of the multiplication) */
add r4, r4, #16
bal _vectoradress /* restores the original adress for the vector, to start over with the vector */
cmp r6, #4 /* compares r6 and 4, if they are equal we have multiplied all that matters */
bne loop /* goes back to loop if r6 and r4 were not equal, because we are not done yet, YOLO */
mov r1, r3
mov r2, #50
mov r7, #4
mov r7,#1
swi 0x0
Resultat:
.word adressR
/ * e.o.f. * /