所以这是一个使用递归的斐波那契程序,但最后有一个“分段错误(代码转储)”。是什么原因造成的?编码:
_start:
mov eax, 4 ; ask for a number
mov ebx, 1
mov ecx, prompt
mov edx, promptLen
int 80h
mov eax, 3 ; scan input
mov ebx, 0
mov ecx, n
int 80h
sub byte [n], 30h
mov esi, 1
push word 0
push word [n]
call fibo
exit:
mov eax, 1
mov ebx, 0
int 80h
fibo:
mov ebp, esp
mov edi, [ebp+6]
add byte [ebp+6],30h
mov eax, 4 ; print number
mov ebx, 1
lea ecx, [ebp+6]
mov edx, 1
int 80h
sub byte [ebp+6],30h
mov eax, 4 ; print space
mov ebx, 1
mov ecx, space
mov edx, 1
int 80h
cmp byte [ebp+4],0
je bye
add [ebp+6],esi
mov esi, edi
push word [ebp+6]
dec word [ebp+4]
push word [ebp+4]
call fibo
bye:
ret 4
样本输出:
Enter a number: 5
0 1 1 2 3 5 Segmentation fault (code dumped)
输出数字是正确的,但是是什么导致了 seg 错误?