-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci.asm
More file actions
114 lines (102 loc) · 1.57 KB
/
Copy pathfibonacci.asm
File metadata and controls
114 lines (102 loc) · 1.57 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
section .text
global _start
_start:
;To print the msg1
mov eax , 4
mov ebx , 1
mov ecx , msg
mov edx , len
int 0x80
; Print the 1st number
mov eax , [x]
mov edi, sum
call int2str
sub edi, sum
mov [sum_len], edi
mov eax , 4
mov ebx , 1
mov ecx , sum
mov edx , [sum_len]
int 0x80
mov eax , 4
mov ebx , 1
mov ecx , msg2
mov edx , len2
int 0x80
; Print the 2nd number
mov eax , [y]
mov edi, sum
call int2str
sub edi, sum
mov [sum_len], edi
mov eax , 4
mov ebx , 1
mov ecx , sum
mov edx , [sum_len]
int 0x80
mov eax , 4
mov ebx , 1
mov ecx , msg2
mov edx , len2
int 0x80
mov ecx , [range]
sub ecx , 2
fib_loop:
mov [range] , ecx
mov eax , [x]
mov ebx , [y]
add eax , ebx
mov ebx , [y]
mov [x] , ebx
mov [y] , eax
mov edi, sum
call int2str
sub edi, sum
mov [sum_len], edi
mov eax , 4
mov ebx , 1
mov ecx , sum
mov edx , [sum_len]
int 0x80
mov eax , 4
mov ebx , 1
mov ecx , msg2
mov edx , len2
int 0x80
mov ecx , [range]
dec ecx
jne fib_loop
mov eax, 1
int 0x80
;to Print the Number greater than 9
int2str:
xor ecx, ecx
mov ebx, 10
.LL1:
xor edx, edx
div ebx
push dx
inc ecx
test eax, eax
jnz .LL1
.LL2:
pop dx
or dl, '0'
mov [edi], dl
inc edi
loop .LL2
mov byte [edi], 0
ret
section .data
x dd 0 ;First Number
y dd 1 ;Second Number
range dd 15
msg db "The Fibonacci Sequence is : " ;Message to Print
len equ $-msg ;Length of message
msg2 db " " ;Like to give space after every number
len2 equ $-msg2
msg3 db "Enter the Range : "
len3 equ $-msg3
segment .bss
sum resb 40
sum_len resd 1