-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursive-fn-call.asm
More file actions
53 lines (43 loc) · 906 Bytes
/
recursive-fn-call.asm
File metadata and controls
53 lines (43 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
BITS 32
extern printf
extern scanf
section .rodata:
formatOut : db "%d", 10, 0
formatIn : db "%d", 0
section .text
global main
main:
push ebp
mov ebp, esp
sub esp, 8
lea eax, [ebp-0x4]
push eax
push formatIn
call scanf
mov edi, [ebp-0x4]
call fact
mov DWORD [ebp-4], eax
push eax
push formatOut
call printf
add esp, 8
leave
ret
fact:
push ebp
mov ebp, esp
sub esp, 8
mov DWORD [ebp-4], edi
cmp DWORD [ebp-4], 0
jne NEXT
mov eax, 1
jmp END
NEXT:
mov eax, DWORD [ebp-4]
sub eax, 1
mov edi, eax
call fact
imul eax, DWORD [ebp-4]
END:
leave
ret