我正在使用ARMV8进行编码。我几乎完成了我的代码,除了我遇到了一个问题。运行代码时,我会得到"分割故障(核心倾倒)"错误。之所以出现问题,是因为当线路对//a执行时,它将非常大的数字存储到x24中,当时它应该存储一个在0-50之间的数字。因此,在标有一个B和C的线上,该代码试图指向X29 2^40左右的某个地方,而不是x29 (0-50)。
我已经尝试浏览代码以查找错误的数字存储在I_S指针中的位置,但是我找不到它。我还尝试了使用B和C到X21中的X24更改X24的代码,并且运行良好。
最让我感到困惑的部分是,在代码中的此问题之前,我在测试标签后立即有一条几乎相同的代码行。唯一的区别是它的工作原理,我将其存储到X21中,并且它不起作用,它将其存储到X24中。I_S指向从工作负载到损坏的负载的值没有变化。
注意:所讨论的线接近代码的底部
define(SIZE, 50)
define(v_base_r, x19) //stack location of index 0
define(ind_r, x20) //index of array
i_size = 4
j_size = 4
min_size = 4
temp_size = 4
v_size = 50*4
alloc = -(16+i_size+j_size+min_size+temp_size+v_size) & -16
dealloc = -alloc
i_s = 16
j_s = 20
min_s = 24
temp_s = 28
v_s = 32
fmt1: .string "v[%d]: %dn" //i, v[i]
fmt2: .string "nSorted array:n"
fmt3: .string "v[%d]: %dn" //i, v[i]
.balign 4
.global main
main: stp x29, x30, [sp, alloc]!
mov x29, sp
add v_base_r, x29, v_s
mov ind_r, 0 //initialize index to 0
b inittest
init:
bl rand
and w0, w0, 0xFF
str w0, [v_base_r, ind_r, lsl 2]//stores current rand()&&0xFF into v[ind_r]
adrp x0, fmt1
add x0, x0, :lo12:fmt1
mov x1, ind_r
ldr w2, [v_base_r, ind_r, lsl 2]
bl printf //Printing "v[index]: (value at index)"
add ind_r, ind_r, 1 //repeats for index + 1
inittest:
cmp ind_r, SIZE
b.lt init
mov x21, 0
str x21, [x29, i_s] //initialize i to 0
b testOut
forOut:
str x21, [x29, min_s] //x21 is still holding the value of i from testOut
add x22, x21, 1
str x22, [x29, j_s] //initialize j as j = i+1
b testIn
forIn:
ldr x21, [x29, min_s]
ldr w23, [v_base_r, x22, lsl 2] //x22 still stores value of j from testIn
ldr w24, [v_base_r, x21, lsl 2] //x23 and x24 store values in
//v[j] and v[min], respectively
cmp w23, w24
b.ge keep
str x22, [x29, min_s] //value of j (x22) is stored into min
keep:
add x22, x22, 1 //x22 still stores j, so we can increment
str x22, [x29, j_s] //and then store as new j for next iteration
testIn:
ldr x22, [x29, j_s]
cmp x22, SIZE //j < SIZE
b.lt forIn
ldr x21, [x29, min_s]
**ldr x24, [x29, i_s]** //THIS ONE A
ldr w23, [v_base_r, x21, lsl 2]
str w23, [x29, temp_s] //temp = v[min]
**ldr w23, [v_base_r, x24, lsl 2]** //THIS ONE B
str w23, [v_base_r, x21, lsl 2] //v[min] = v[i]
ldr w23, [x29, temp_s]
**str w23, [v_base_r, x24, lsl 2] //v[i] = temp** //THIS ONE C
add x22, x22, 1 //x22 still stores i, so we can increment
str x22, [x29, i_s] //and then store as new i for next iteration
testOut:
ldr x21, [x29, i_s]
cmp x21, SIZE-1 //i < SIZE-1
b.lt forOut
这不是解决我的问题的最佳方法,但对我有用。因此,我猜想,当我为堆栈中存储的每个变量提供空间时,每个整数分配了4个;因此,以下代码:
i_size = 4
j_size = 4
min_size = 4
temp_size = 4
v_size = 50*4
alloc = -(16+i_size+j_size+min_size+temp_size+v_size) & -16
dealloc = -alloc
i_s = 16
j_s = 20
min_s = 24
temp_s = 28
v_s = 32
在I_S的两个读取之间,我以50次运行的循环中将J_S增加1个。当我使用x/4x $x29+16
检查I_S时,第二个十六进制代码在每次迭代中都被1增量。每当代码执行指令str x22, [x29, j_s]
时,它都会增加。
最终解决我的问题的原因是,我将代码的起点更改为:
i_size = 8
j_size = 8
min_size = 8
temp_size = 8
v_size = 50*4
alloc = -(16+i_size+j_size+min_size+temp_size+v_size) & -16
dealloc = -alloc
i_s = 16
j_s = 24
min_s = 32
temp_s = 40
v_s = 48
所以我最终将分配给每个整数的尺寸从4更改为8。过度杀伤,但是我不确定该修复它。
你好,我遇到了相同的错误分割故障(核心倾倒)在运行下面的代码时:
**
section .text
global _start
_start: ;tells linker the entry point
mov edx, len ;message length
mov ecx, msg ;message wo write
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number(sys_write)
int 0*80 ;call kernel
mov edx, 9 ;message length
mov ecx, s2 ;message to write
mov ebx, 1 ;file descriptor(stdout)
mov eax, 4 ;system call number (sys_write)
int 0*80 ;call kernel
mov eax, 1 ;system call number (sys_Exit)
int 0*80 ;call kernel
section .data
msg db 'Dispay 9 stars', 0xa ;a message
len equ $ - msg ;length of message
s2 times 9 db 'x'
**
解决方案:我从 int 0*80 call内核更改为 int 80H 我的错误。