Code1: implements main function which calls fact (factorial) function
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
Code2 which implements fact (factorial function):
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
System stats: 32 bit machine, Ubuntu 14.04, Nasm is used
Problem statement: Program received signal SIGILL, Illegal instruction. Why am I getting this error?
pusha's andpopa's are not even balanced. Check the block containingcall fact. Return will go somewhere interesting this way.