代碼1:實現它調用事實(階乘)功能的主要功能x86彙編遞歸函數 - >非法指令錯誤
section .data
msg db "Enter the Number whose factorial is to be calculated",10,0
msg1 db "The factorial is: ",0
ioput db "%d"
section .bss
a resd 1
section .text
global main
extern printf,scanf,fact
main:
pusha
push msg
call printf
add esp,4
popa
pusha
push a
push ioput
call scanf
add esp,8
popa
mov ebx,dword[a]
pusha
push ebx
call fact
add esp,4
pusha
push msg1
call printf
add esp,4
popa
pusha
push eax
push ioput
call printf
add esp,8
popa
ret
代碼2,它實現事實(階乘函數):
section .text
global fact
extern printf,scanf
fact:
enter 0,0
cmp ebx,1
jnz next
ret
next:
push ebx
dec ebx
call fact
pop ebx
mul eax,ebx
leave
ret
系統統計資料: 32位機器,Ubuntu 14.04,Nasm使用
問題說明:程序收到信號SIGILL
,非法指令。爲什麼我得到這個錯誤?
的'pusha'的和'popa'的甚至不均衡。檢查包含「呼叫事實」的塊。返回將會以這種方式進行。 – harold
另外,學習使用調試器。 – Jester