代码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